/** * @deprecated Use {@link #setInt(CharSequence, int)} instead. * * @see #setIntHeader(HttpMessage, CharSequence, int) */ @Deprecated public static void setIntHeader(HttpMessage message, String name, int value) { message.headers().setInt(name, value); }
/** * @deprecated Use {@link #setInt(CharSequence, int)} instead. * * Sets a new integer header with the specified name and value. If there * is an existing header with the same name, the existing header is removed. */ @Deprecated public static void setIntHeader(HttpMessage message, CharSequence name, int value) { message.headers().setInt(name, value); }
protected void sendHttp1Response0(HttpResponseStatus status, boolean error, ByteBuf content) { FullHttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, status, content); HttpHeaders headers = httpResponse.headers(); headers.setInt(CONTENT_LENGTH, httpResponse.content().readableBytes()); if (request.getSerializeType() > 0) { String serialization = SerializerFactory.getAliasByCode(request.getSerializeType()); headers.set(RemotingConstants.HEAD_SERIALIZE_TYPE, serialization); } else { headers.set(CONTENT_TYPE, "text/plain; charset=" + RpcConstants.DEFAULT_CHARSET.displayName()); } if (error) { headers.set(RemotingConstants.HEAD_RESPONSE_ERROR, "true"); } if (!keepAlive) { ctx.write(httpResponse).addListener(ChannelFutureListener.CLOSE); } else { httpResponse.headers().set(CONNECTION, HttpHeaderValues.KEEP_ALIVE); ctx.write(httpResponse); } } }
protected void sendHttp1Response0(HttpResponseStatus status, boolean error, ByteBuf content) { FullHttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, status, content); HttpHeaders headers = httpResponse.headers(); headers.setInt(CONTENT_LENGTH, httpResponse.content().readableBytes()); if (request.getSerializeType() > 0) { String serialization = SerializerFactory.getAliasByCode(request.getSerializeType()); headers.set(RemotingConstants.HEAD_SERIALIZE_TYPE, serialization); } else { headers.set(CONTENT_TYPE, "text/plain; charset=" + RpcConstants.DEFAULT_CHARSET.displayName()); } if (error) { headers.set(RemotingConstants.HEAD_RESPONSE_ERROR, "true"); } if (!keepAlive) { ctx.write(httpResponse).addListener(ChannelFutureListener.CLOSE); } else { httpResponse.headers().set(CONNECTION, HttpHeaderValues.KEEP_ALIVE); ctx.write(httpResponse); } } }
@Override protected void encode(ChannelHandlerContext ctx, HttpMessage msg, List<Object> out) throws Exception { Integer id = ids.poll(); if (id != null && id.intValue() != NO_ID && !msg.headers().contains(SpdyHttpHeaders.Names.STREAM_ID)) { msg.headers().setInt(Names.STREAM_ID, id); } out.add(ReferenceCountUtil.retain(msg)); }
httpResponse.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, httpResponse.content().readableBytes()); httpResponse.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE); ctx.write(httpResponse);
@Override protected void sanitizeHeadersBeforeEncode(HttpResponse msg, boolean isAlwaysEmpty) { if (isAlwaysEmpty) { HttpResponseStatus status = msg.status(); if (status.codeClass() == HttpStatusClass.INFORMATIONAL || status.code() == HttpResponseStatus.NO_CONTENT.code()) { // Stripping Content-Length: // See https://tools.ietf.org/html/rfc7230#section-3.3.2 msg.headers().remove(HttpHeaderNames.CONTENT_LENGTH); // Stripping Transfer-Encoding: // See https://tools.ietf.org/html/rfc7230#section-3.3.1 msg.headers().remove(HttpHeaderNames.TRANSFER_ENCODING); } else if (status.code() == HttpResponseStatus.RESET_CONTENT.code()) { // Stripping Transfer-Encoding: msg.headers().remove(HttpHeaderNames.TRANSFER_ENCODING); // Set Content-Length: 0 // https://httpstatuses.com/205 msg.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, 0); } } }
@Override public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endOfStream) throws Http2Exception { Http2Stream stream = connection.stream(streamId); FullHttpMessage msg = processHeadersBegin(ctx, stream, headers, endOfStream, true, true); if (msg != null) { // Add headers for dependency and weight. // See https://github.com/netty/netty/issues/5866 if (streamDependency != Http2CodecUtil.CONNECTION_STREAM_ID) { msg.headers().setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), streamDependency); } msg.headers().setShort(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), weight); processHeadersEnd(ctx, stream, msg, endOfStream); } }
httpRequestWithEntity.headers().setInt(Names.STREAM_ID, streamId); httpRequestWithEntity.headers().setInt(Names.ASSOCIATED_TO_STREAM_ID, associatedToStreamId); httpRequestWithEntity.headers().setInt(Names.PRIORITY, spdySynStreamFrame.priority()); httpRequestWithEntity.headers().setInt(Names.STREAM_ID, streamId); httpResponseWithEntity.headers().setInt(Names.STREAM_ID, streamId); fullHttpMessage.headers().setInt(Names.STREAM_ID, streamId);
outputHeaders.remove(HttpHeaderNames.TRAILER); if (!isTrailer) { outputHeaders.setInt(ExtensionHeaderNames.STREAM_ID.text(), streamId); HttpUtil.setKeepAlive(outputHeaders, httpVersion, true);
@Test public void shouldRejectIfHttp() { // Given BoltProtocol protocol = newBoltProtocol( 1 ); BoltProtocolFactory handlerFactory = newProtocolFactory( 1, protocol ); EmbeddedChannel channel = new EmbeddedChannel( new ProtocolHandshaker( handlerFactory, boltChannel, logProvider, false, true ) ); // When FullHttpRequest request = new DefaultFullHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.POST, "http://hello_world:10000" ); request.headers().setInt( HttpHeaderNames.CONTENT_LENGTH, 0 ); channel.writeInbound( request ); // Then assertEquals( 0, channel.outboundMessages().size() ); assertFalse( channel.isActive() ); verify( protocol, never() ).install(); logProvider.assertExactly( AssertableLogProvider.inLog( ProtocolHandshaker.class ).warn( "Unsupported connection type: 'HTTP'. Bolt protocol only operates over a TCP connection or WebSocket." ) ); }
outHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
@Override public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception { // A push promise should not be allowed to add headers to an existing stream Http2Stream promisedStream = connection.stream(promisedStreamId); if (headers.status() == null) { // A PUSH_PROMISE frame has no Http response status. // https://tools.ietf.org/html/rfc7540#section-8.2.1 // Server push is semantically equivalent to a server responding to a // request; however, in this case, that request is also sent by the // server, as a PUSH_PROMISE frame. headers.status(OK.codeAsText()); } FullHttpMessage msg = processHeadersBegin(ctx, promisedStream, headers, false, false, false); if (msg == null) { throw connectionError(PROTOCOL_ERROR, "Push Promise Frame received for pre-existing stream id %d", promisedStreamId); } msg.headers().setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_PROMISE_ID.text(), streamId); msg.headers().setShort(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT); processHeadersEnd(ctx, promisedStream, msg, false); }
upgrade.upgradeRequest().headers().setInt( HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), HTTP_UPGRADE_STREAM_ID); stream.setProperty(upgradeKey, true);
upgrade.upgradeRequest().headers().setInt( HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), HTTP_UPGRADE_STREAM_ID); stream.setProperty(upgradeKey, true);
upgrade.upgradeRequest().headers().setInt( HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), HTTP_UPGRADE_STREAM_ID); stream.setProperty(upgradeKey, true);
response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, fullHttpResponse.content().readableBytes()); if (keepAlive) {
/** * @deprecated Use {@link #setInt(CharSequence, int)} instead. * * @see #setIntHeader(HttpMessage, CharSequence, int) */ @Deprecated public static void setIntHeader(HttpMessage message, String name, int value) { message.headers().setInt(name, value); }
/** * @deprecated Use {@link #setInt(CharSequence, int)} instead. * * Sets a new integer header with the specified name and value. If there * is an existing header with the same name, the existing header is removed. */ @Deprecated public static void setIntHeader(HttpMessage message, CharSequence name, int value) { message.headers().setInt(name, value); }
@Override protected void encode(ChannelHandlerContext ctx, HttpMessage msg, List<Object> out) throws Exception { Integer id = ids.poll(); if (id != null && id.intValue() != NO_ID && !msg.headers().contains(SpdyHttpHeaders.Names.STREAM_ID)) { msg.headers().setInt(Names.STREAM_ID, id); } out.add(ReferenceCountUtil.retain(msg)); }