use of com.netflix.zuul.message.Header in project zuul by Netflix.
the class ClientResponseWriter method buildHttpResponse.
private HttpResponse buildHttpResponse(final HttpResponseMessage zuulResp) {
final HttpRequestInfo zuulRequest = zuulResp.getInboundRequest();
HttpVersion responseHttpVersion;
final String inboundProtocol = zuulRequest.getProtocol();
if (inboundProtocol.startsWith("HTTP/1")) {
responseHttpVersion = HttpVersion.valueOf(inboundProtocol);
} else {
// Default to 1.1. We do this to cope with HTTP/2 inbound requests.
responseHttpVersion = HttpVersion.HTTP_1_1;
}
// Create the main http response to send, with body.
final DefaultHttpResponse nativeResponse = new DefaultHttpResponse(responseHttpVersion, HttpResponseStatus.valueOf(zuulResp.getStatus()), false, false);
// Now set all of the response headers - note this is a multi-set in keeping with HTTP semantics
final HttpHeaders nativeHeaders = nativeResponse.headers();
for (Header entry : zuulResp.getHeaders().entries()) {
nativeHeaders.add(entry.getKey(), entry.getValue());
}
// Netty does not automatically add Content-Length or Transfer-Encoding: chunked. So we add here if missing.
if (!HttpUtil.isContentLengthSet(nativeResponse) && !HttpUtil.isTransferEncodingChunked(nativeResponse)) {
nativeResponse.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
}
final HttpRequest nativeReq = (HttpRequest) zuulResp.getContext().get(CommonContextKeys.NETTY_HTTP_REQUEST);
if (!closeConnection && HttpUtil.isKeepAlive(nativeReq)) {
HttpUtil.setKeepAlive(nativeResponse, true);
} else {
// Send a Connection: close response header (only needed for HTTP/1.0 but no harm in doing for 1.1 too).
nativeResponse.headers().set("Connection", "close");
}
// TODO - temp hack for http/2 handling.
if (nativeReq.headers().contains(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text())) {
String streamId = nativeReq.headers().get(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text());
nativeResponse.headers().set(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), streamId);
}
return nativeResponse;
}
use of com.netflix.zuul.message.Header in project zuul by Netflix.
the class OriginResponseReceiver method buildOriginHttpRequest.
private HttpRequest buildOriginHttpRequest(final HttpRequestMessage zuulRequest) {
final String method = zuulRequest.getMethod().toUpperCase();
final String uri = pathAndQueryString(zuulRequest);
customRequestProcessing(zuulRequest);
final DefaultHttpRequest nettyReq = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.valueOf(method), uri, false);
// Copy headers across.
for (final Header h : zuulRequest.getHeaders().entries()) {
nettyReq.headers().add(h.getKey(), h.getValue());
}
return nettyReq;
}
use of com.netflix.zuul.message.Header in project zuul by Netflix.
the class Debug method writeDebugMessage.
public static Observable<Boolean> writeDebugMessage(SessionContext context, ZuulMessage msg, String prefix, String arrow) {
Observable<Boolean> obs = null;
for (Header header : msg.getHeaders().entries()) {
Debug.addRequestDebug(context, String.format("%s:: %s HDR: %s:%s", prefix, arrow, header.getKey(), header.getValue()));
}
// Capture the response body into a Byte array for later usage.
if (msg.hasBody()) {
if (!Debug.debugRequestHeadersOnly(context)) {
// Convert body to a String and add to debug log.
String body = msg.getBodyAsText();
Debug.addRequestDebug(context, String.format("%s:: %s BODY: %s", prefix, arrow, body));
}
}
if (obs == null)
obs = Observable.just(Boolean.FALSE);
return obs;
}
use of com.netflix.zuul.message.Header in project zuul by Netflix.
the class Debug method addRequestDebugForMessage.
public static void addRequestDebugForMessage(SessionContext ctx, ZuulMessage message, String prefix) {
for (Header header : message.getHeaders().entries()) {
Debug.addRequestDebug(ctx, prefix + " " + header.getKey() + " " + header.getValue());
}
if (message.hasBody()) {
String bodyStr = message.getBodyAsText();
Debug.addRequestDebug(ctx, prefix + " " + bodyStr);
}
}
use of com.netflix.zuul.message.Header in project zuul by Netflix.
the class HttpResponseMessageImpl method removeExistingSetCookie.
@Override
public boolean removeExistingSetCookie(String cookieName) {
String cookieNamePrefix = cookieName + "=";
boolean dirty = false;
Headers filtered = new Headers();
for (Header hdr : getHeaders().entries()) {
if (HttpHeaderNames.SET_COOKIE.equals(hdr.getName())) {
String value = hdr.getValue();
// Strip out this set-cookie as requested.
if (value.startsWith(cookieNamePrefix)) {
// Don't copy it.
dirty = true;
} else {
// Copy all other headers.
filtered.add(hdr.getName(), hdr.getValue());
}
} else {
// Copy all other headers.
filtered.add(hdr.getName(), hdr.getValue());
}
}
if (dirty) {
setHeaders(filtered);
}
return dirty;
}
Aggregations