本文整理匯總了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);
}