本文整理汇总了Java中io.vertx.core.http.HttpServerResponse.setChunked方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerResponse.setChunked方法的具体用法?Java HttpServerResponse.setChunked怎么用?Java HttpServerResponse.setChunked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.http.HttpServerResponse
的用法示例。
在下文中一共展示了HttpServerResponse.setChunked方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: proxyUserRequest
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
/**
* Proxies the specified HTTP request, enriching its headers with authentication information.
*
* @param userId the ID of the user making the request.
* @param origReq the original request (i.e., {@link RoutingContext#request()}.
* @param origRes the original response (i.e., {@link RoutingContext#request()}.
*/
public void proxyUserRequest(final String userId,
final HttpServerRequest origReq,
final HttpServerResponse origRes) {
final Handler<HttpClientResponse> proxiedResHandler = proxiedRes -> {
origRes.setChunked(true);
origRes.setStatusCode(proxiedRes.statusCode());
origRes.headers().setAll(proxiedRes.headers());
proxiedRes.handler(origRes::write);
proxiedRes.endHandler(v -> origRes.end());
};
final HttpClientRequest proxiedReq;
proxiedReq = httpClient.request(origReq.method(), port, host, origReq.uri(), proxiedResHandler);
proxiedReq.setChunked(true);
proxiedReq.headers().add(X_FORWARDED_PROTO, getHeader(origReq, X_FORWARDED_PROTO, origReq.scheme()));
proxiedReq.headers().add(X_FORWARDED_FOR, getHeader(origReq, X_FORWARDED_FOR, origReq.remoteAddress().host()));
proxiedReq.headers().addAll(origReq.headers());
injectRutHeader(proxiedReq, userId);
origReq.handler(proxiedReq::write);
origReq.endHandler(v -> proxiedReq.end());
}
示例2: addChunkedIfNeeded
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
private void addChunkedIfNeeded() {
if (stream instanceof HttpServerResponse) {
final HttpServerResponse resp = (HttpServerResponse) stream;
if (resp.headers().get(HttpHeaders.CONTENT_LENGTH) == null) {
resp.setChunked(true);
}
} else if (stream instanceof HttpClientRequest) {
final HttpClientRequest req = (HttpClientRequest) stream;
if (req.headers().get(HttpHeaders.CONTENT_LENGTH) == null) {
req.setChunked(true);
}
}
}
示例3: handle
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
public void handle(HttpServerRequest clientRequest, HttpServerResponse clientResponse,
HttpResponse<Buffer> appResponse) {
int statusCode = appResponse.statusCode();
clientResponse.setStatusCode(statusCode);
// clientResponse.setStatusMessage(appResponse.statusMessage());
// System.out.println(appResponse.statusMessage());
MultiMap appHeaders = appResponse.headers();
appHeaders.forEach(entry -> {
String k = entry.getKey();
String v = entry.getValue();
// System.out.println("Header Response:[" + k + "]=" + v);
if ("Location".equalsIgnoreCase(k) && S.isNotBlank(v)) {
String schemal = clientRequest.scheme();
String host = clientRequest.host();
clientResponse.putHeader("Location", v.replaceAll(HTTP_SCHEMAL_HOST_REG, schemal + "://" + host + "/"));
} else
clientResponse.putHeader(k, v);
});
clientResponse.setChunked(true);
Buffer buff = appResponse.bodyAsBuffer();
if (buff != null && buff.length() > 0)
clientResponse.write(buff);
}