本文整理汇总了Java中io.netty.handler.codec.http.HttpHeaders.setTransferEncodingChunked方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaders.setTransferEncodingChunked方法的具体用法?Java HttpHeaders.setTransferEncodingChunked怎么用?Java HttpHeaders.setTransferEncodingChunked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.handler.codec.http.HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.setTransferEncodingChunked方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeResponse
import io.netty.handler.codec.http.HttpHeaders; //导入方法依赖的package包/类
private void writeResponse(boolean lastContent) {
HttpResponse response = servletResponse.getNettyResponse();
// TODO implement exceptions required by http://tools.ietf.org/html/rfc2616#section-4.4
if (!HttpHeaders.isContentLengthSet(response)) {
if (lastContent) {
HttpHeaders.setContentLength(response, count);
} else {
HttpHeaders.setTransferEncodingChunked(response);
}
}
ctx.write(response, ctx.voidPromise());
}
示例2: writeResponse
import io.netty.handler.codec.http.HttpHeaders; //导入方法依赖的package包/类
private void writeResponse(boolean lastContent) {
HttpResponse response = servletResponse.getNettyResponse();
// TODO implement exceptions required by container://tools.ietf.org/html/rfc2616#section-4.4
if (!HttpHeaders.isContentLengthSet(response)) {
if (lastContent) {
HttpHeaders.setContentLength(response, count);
} else {
HttpHeaders.setTransferEncodingChunked(response);
}
}
ctx.write(response, ctx.voidPromise());
}
示例3: respond
import io.netty.handler.codec.http.HttpHeaders; //导入方法依赖的package包/类
/**
* Send a response to the client.
*
* @param serverConnection
* the ProxyToServerConnection that's responding
* @param filters
* the filters to apply to the response
* @param currentHttpRequest
* the HttpRequest that prompted this response
* @param currentHttpResponse
* the HttpResponse corresponding to this data (when doing
* chunked transfers, this is the initial HttpResponse object
* that came in before the other chunks)
* @param httpObject
* the data with which to respond
*/
void respond(ProxyToServerConnection serverConnection, HttpFilters filters,
HttpRequest currentHttpRequest, HttpResponse currentHttpResponse,
HttpObject httpObject) {
// we are sending a response to the client, so we are done handling this request
this.currentRequest = null;
httpObject = filters.serverToProxyResponse(httpObject);
if (httpObject == null) {
forceDisconnect(serverConnection);
return;
}
if (httpObject instanceof HttpResponse) {
HttpResponse httpResponse = (HttpResponse) httpObject;
// if this HttpResponse does not have any means of signaling the end of the message body other than closing
// the connection, convert the message to a "Transfer-Encoding: chunked" HTTP response. This avoids the need
// to close the client connection to indicate the end of the message. (Responses to HEAD requests "must be" empty.)
if (!ProxyUtils.isHead(currentHttpRequest) && !ProxyUtils.isResponseSelfTerminating(httpResponse)) {
// if this is not a FullHttpResponse, duplicate the HttpResponse from the server before sending it to
// the client. this allows us to set the Transfer-Encoding to chunked without interfering with netty's
// handling of the response from the server. if we modify the original HttpResponse from the server,
// netty will not generate the appropriate LastHttpContent when it detects the connection closure from
// the server (see HttpObjectDecoder#decodeLast). (This does not apply to FullHttpResponses, for which
// netty already generates the empty final chunk when Transfer-Encoding is chunked.)
if (!(httpResponse instanceof FullHttpResponse)) {
HttpResponse duplicateResponse = ProxyUtils.duplicateHttpResponse(httpResponse);
// set the httpObject and httpResponse to the duplicated response, to allow all other standard processing
// (filtering, header modification for proxying, etc.) to be applied.
httpObject = httpResponse = duplicateResponse;
}
HttpHeaders.setTransferEncodingChunked(httpResponse);
}
fixHttpVersionHeaderIfNecessary(httpResponse);
modifyResponseHeadersToReflectProxying(httpResponse);
}
httpObject = filters.proxyToClientResponse(httpObject);
if (httpObject == null) {
forceDisconnect(serverConnection);
return;
}
write(httpObject);
if (ProxyUtils.isLastChunk(httpObject)) {
writeEmptyBuffer();
}
closeConnectionsAfterWriteIfNecessary(serverConnection,
currentHttpRequest, currentHttpResponse, httpObject);
}