use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project netty by netty.
the class SpdyHttpEncoder method createHeadersFrame.
@SuppressWarnings("deprecation")
private SpdyHeadersFrame createHeadersFrame(HttpResponse httpResponse) throws Exception {
// Get the Stream-ID from the headers
final HttpHeaders httpHeaders = httpResponse.headers();
int streamId = httpHeaders.getInt(SpdyHttpHeaders.Names.STREAM_ID);
httpHeaders.remove(SpdyHttpHeaders.Names.STREAM_ID);
// The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
// headers are not valid and MUST not be sent.
httpHeaders.remove(HttpHeaderNames.CONNECTION);
httpHeaders.remove("Keep-Alive");
httpHeaders.remove("Proxy-Connection");
httpHeaders.remove(HttpHeaderNames.TRANSFER_ENCODING);
SpdyHeadersFrame spdyHeadersFrame;
if (SpdyCodecUtil.isServerId(streamId)) {
spdyHeadersFrame = new DefaultSpdyHeadersFrame(streamId, validateHeaders);
} else {
spdyHeadersFrame = new DefaultSpdySynReplyFrame(streamId, validateHeaders);
}
SpdyHeaders frameHeaders = spdyHeadersFrame.headers();
// Unfold the first line of the response into name/value pairs
frameHeaders.set(SpdyHeaders.HttpNames.STATUS, httpResponse.status().codeAsText());
frameHeaders.set(SpdyHeaders.HttpNames.VERSION, httpResponse.protocolVersion().text());
// Transfer the remaining HTTP headers
Iterator<Entry<CharSequence, CharSequence>> itr = httpHeaders.iteratorCharSequence();
while (itr.hasNext()) {
Map.Entry<CharSequence, CharSequence> entry = itr.next();
final CharSequence headerName = headersToLowerCase ? AsciiString.of(entry.getKey()).toLowerCase() : entry.getKey();
spdyHeadersFrame.headers().add(headerName, entry.getValue());
}
currentStreamId = streamId;
spdyHeadersFrame.setLast(isLast(httpResponse));
return spdyHeadersFrame;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project netty by netty.
the class SpdyHttpEncoder method createSynStreamFrame.
@SuppressWarnings("deprecation")
private SpdySynStreamFrame createSynStreamFrame(HttpRequest httpRequest) throws Exception {
// Get the Stream-ID, Associated-To-Stream-ID, Priority, and scheme from the headers
final HttpHeaders httpHeaders = httpRequest.headers();
int streamId = httpHeaders.getInt(SpdyHttpHeaders.Names.STREAM_ID);
int associatedToStreamId = httpHeaders.getInt(SpdyHttpHeaders.Names.ASSOCIATED_TO_STREAM_ID, 0);
byte priority = (byte) httpHeaders.getInt(SpdyHttpHeaders.Names.PRIORITY, 0);
CharSequence scheme = httpHeaders.get(SpdyHttpHeaders.Names.SCHEME);
httpHeaders.remove(SpdyHttpHeaders.Names.STREAM_ID);
httpHeaders.remove(SpdyHttpHeaders.Names.ASSOCIATED_TO_STREAM_ID);
httpHeaders.remove(SpdyHttpHeaders.Names.PRIORITY);
httpHeaders.remove(SpdyHttpHeaders.Names.SCHEME);
// The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
// headers are not valid and MUST not be sent.
httpHeaders.remove(HttpHeaderNames.CONNECTION);
httpHeaders.remove("Keep-Alive");
httpHeaders.remove("Proxy-Connection");
httpHeaders.remove(HttpHeaderNames.TRANSFER_ENCODING);
SpdySynStreamFrame spdySynStreamFrame = new DefaultSpdySynStreamFrame(streamId, associatedToStreamId, priority, validateHeaders);
// Unfold the first line of the message into name/value pairs
SpdyHeaders frameHeaders = spdySynStreamFrame.headers();
frameHeaders.set(SpdyHeaders.HttpNames.METHOD, httpRequest.method().name());
frameHeaders.set(SpdyHeaders.HttpNames.PATH, httpRequest.uri());
frameHeaders.set(SpdyHeaders.HttpNames.VERSION, httpRequest.protocolVersion().text());
// Replace the HTTP host header with the SPDY host header
CharSequence host = httpHeaders.get(HttpHeaderNames.HOST);
httpHeaders.remove(HttpHeaderNames.HOST);
frameHeaders.set(SpdyHeaders.HttpNames.HOST, host);
// Set the SPDY scheme header
if (scheme == null) {
scheme = "https";
}
frameHeaders.set(SpdyHeaders.HttpNames.SCHEME, scheme);
// Transfer the remaining HTTP headers
Iterator<Entry<CharSequence, CharSequence>> itr = httpHeaders.iteratorCharSequence();
while (itr.hasNext()) {
Map.Entry<CharSequence, CharSequence> entry = itr.next();
final CharSequence headerName = headersToLowerCase ? AsciiString.of(entry.getKey()).toLowerCase() : entry.getKey();
frameHeaders.add(headerName, entry.getValue());
}
currentStreamId = spdySynStreamFrame.streamId();
if (associatedToStreamId == 0) {
spdySynStreamFrame.setLast(isLast(httpRequest));
} else {
spdySynStreamFrame.setUnidirectional(true);
}
return spdySynStreamFrame;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project netty by netty.
the class HttpToHttp2ConnectionHandlerTest method testAuthorityFormRequestTargetHandled.
@Test
public void testAuthorityFormRequestTargetHandled() throws Exception {
bootstrapEnv(2, 1, 0);
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, CONNECT, "http://www.example.com:80");
final HttpHeaders httpHeaders = request.headers();
httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("CONNECT")).path(new AsciiString("/")).scheme(new AsciiString("http")).authority(new AsciiString("www.example.com:80"));
ChannelPromise writePromise = newPromise();
verifyHeadersOnly(http2Headers, writePromise, clientChannel.writeAndFlush(request, writePromise));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project netty by netty.
the class HttpToHttp2ConnectionHandlerTest method testHeadersOnlyRequest.
@Test
public void testHeadersOnlyRequest() throws Exception {
bootstrapEnv(2, 1, 0);
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "http://my-user_name@www.example.org:5555/example");
final HttpHeaders httpHeaders = request.headers();
httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
httpHeaders.set(HttpHeaderNames.HOST, "my-user_name@www.example.org:5555");
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http");
httpHeaders.add(of("foo"), of("goo"));
httpHeaders.add(of("foo"), of("goo2"));
httpHeaders.add(of("foo2"), of("goo2"));
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/example")).authority(new AsciiString("www.example.org:5555")).scheme(new AsciiString("http")).add(new AsciiString("foo"), new AsciiString("goo")).add(new AsciiString("foo"), new AsciiString("goo2")).add(new AsciiString("foo2"), new AsciiString("goo2"));
ChannelPromise writePromise = newPromise();
verifyHeadersOnly(http2Headers, writePromise, clientChannel.writeAndFlush(request, writePromise));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project netty by netty.
the class HttpToHttp2ConnectionHandlerTest method testNoSchemeRequestTargetHandled.
@Test
public void testNoSchemeRequestTargetHandled() throws Exception {
bootstrapEnv(2, 1, 0);
final FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/");
final HttpHeaders httpHeaders = request.headers();
httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
httpHeaders.set(HttpHeaderNames.HOST, "localhost");
ChannelPromise writePromise = newPromise();
ChannelFuture writeFuture = clientChannel.writeAndFlush(request, writePromise);
assertTrue(writePromise.awaitUninterruptibly(WAIT_TIME_SECONDS, SECONDS));
assertTrue(writePromise.isDone());
assertFalse(writePromise.isSuccess());
assertTrue(writeFuture.isDone());
assertFalse(writeFuture.isSuccess());
}
Aggregations