public static Http2Headers toHttp2Headers(FullHttpMessage in) {
final Http2Headers out = new DefaultHttp2Headers();
HttpHeaders inHeaders = in.headers();
if (in instanceof HttpRequest) {
HttpRequest request = (HttpRequest) in;
out.path(new AsciiString(request.uri()));
out.method(new AsciiString(request.method().toString()));
String value = inHeaders.getAndConvert(HttpHeaderNames.HOST);
if (value != null) {
URI hostUri = URI.create(value);
// The authority MUST NOT include the deprecated "userinfo" subcomponent
value = hostUri.getAuthority();
if (value != null) {
out.authority(new AsciiString(value.replaceFirst("^.*@", "")));
}
value = hostUri.getScheme();
if (value != null) {
out.scheme(new AsciiString(value));
}
}
// Consume the Authority extension header if present
CharSequence cValue = inHeaders.get(ExtensionHeaderNames.AUTHORITY.text());
if (cValue != null) {
out.authority(AsciiString.of(cValue));
}
// Consume the Scheme extension header if present
cValue = inHeaders.get(ExtensionHeaderNames.SCHEME.text());
if (cValue != null) {
out.scheme(AsciiString.of(cValue));
}
} else if (in instanceof HttpResponse) {
HttpResponse response = (HttpResponse) in;
out.status(new AsciiString(Integer.toString(response.status().code())));
}
// Add the HTTP headers which have not been consumed above
try {
inHeaders.forEachEntry(new EntryVisitor() {
@Override
public boolean visit(Entry<CharSequence, CharSequence> entry) throws Exception {
final AsciiString aName = AsciiString.of(entry.getKey()).toLowerCase();
if (!HTTP_TO_HTTP2_HEADER_BLACKLIST.contains(aName)) {
AsciiString aValue = AsciiString.of(entry.getValue());
out.add(aName, aValue);
}
return true;
}
});