use of com.netflix.zuul.message.Headers in project zuul by Netflix.
the class DebugTest method setup.
@Before
public void setup() {
ctx = new SessionContext();
headers = new Headers();
headers.add("lah", "deda");
params = new HttpQueryParams();
params.add("k1", "v1");
request = new HttpRequestBuilder(ctx).withMethod(HttpMethod.POST).withUri("/some/where").withHeaders(headers).withQueryParams(params).build();
request.setBodyAsText("some text");
request.storeInboundRequest();
response = new HttpResponseMessageImpl(ctx, headers, request, 200);
response.setBodyAsText("response text");
}
use of com.netflix.zuul.message.Headers in project zuul by Netflix.
the class GZipResponseFilter method shouldFilter.
@Override
public boolean shouldFilter(HttpResponseMessage response) {
if (!ENABLED.get() || !response.hasBody() || response.getContext().isInBrownoutMode()) {
return false;
}
if (response.getContext().get(CommonContextKeys.GZIPPER) != null) {
return true;
}
// A flag on SessionContext can be set to override normal mechanism of checking if client accepts gzip.;
final HttpRequestInfo request = response.getInboundRequest();
final Boolean overrideIsGzipRequested = (Boolean) response.getContext().get(CommonContextKeys.OVERRIDE_GZIP_REQUESTED);
final boolean isGzipRequested = (overrideIsGzipRequested == null) ? HttpUtils.acceptsGzip(request.getHeaders()) : overrideIsGzipRequested.booleanValue();
// Check the headers to see if response is already gzipped.
final Headers respHeaders = response.getHeaders();
boolean isResponseCompressed = HttpUtils.isCompressed(respHeaders);
// Decide what to do.;
final boolean shouldGzip = isGzippableContentType(response) && isGzipRequested && !isResponseCompressed && isRightSizeForGzip(response);
if (shouldGzip) {
response.getContext().set(CommonContextKeys.GZIPPER, getGzipper());
}
return shouldGzip;
}
use of com.netflix.zuul.message.Headers in project zuul by Netflix.
the class StatsManagerTest method testCollectRequestStats.
@Test
public void testCollectRequestStats() {
final String host = "api.netflix.com";
final String proto = "https";
final HttpRequestInfo req = Mockito.mock(HttpRequestInfo.class);
Headers headers = new Headers();
when(req.getHeaders()).thenReturn(headers);
headers.set(StatsManager.HOST_HEADER, host);
headers.set(StatsManager.X_FORWARDED_PROTO_HEADER, proto);
when(req.getClientIp()).thenReturn("127.0.0.1");
final StatsManager sm = StatsManager.getManager();
sm.collectRequestStats(req);
final NamedCountingMonitor hostMonitor = sm.getHostMonitor(host);
assertNotNull("hostMonitor should not be null", hostMonitor);
final NamedCountingMonitor protoMonitor = sm.getProtocolMonitor(proto);
assertNotNull("protoMonitor should not be null", protoMonitor);
assertEquals(1, hostMonitor.getCount());
assertEquals(1, protoMonitor.getCount());
}
use of com.netflix.zuul.message.Headers in project zuul by Netflix.
the class ClientRequestReceiver method write.
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
try (TaskCloseable ignored = PerfMark.traceTask("CRR.write")) {
if (msg instanceof HttpResponse) {
promise.addListener((future) -> {
if (!future.isSuccess()) {
fireWriteError("response headers", future.cause(), ctx);
}
});
super.write(ctx, msg, promise);
} else if (msg instanceof HttpContent) {
promise.addListener((future) -> {
if (!future.isSuccess()) {
fireWriteError("response content", future.cause(), ctx);
}
});
super.write(ctx, msg, promise);
} else {
// should never happen
ReferenceCountUtil.release(msg);
throw new ZuulException("Attempt to write invalid content type to client: " + msg.getClass().getSimpleName(), true);
}
}
}
use of com.netflix.zuul.message.Headers in project zuul by Netflix.
the class ProxyUtils method addXForwardedHeaders.
public static void addXForwardedHeaders(HttpRequestMessage request) {
// Add standard Proxy request headers.
Headers headers = request.getHeaders();
addXForwardedHeader(headers, HttpHeaderNames.X_FORWARDED_HOST, request.getOriginalHost());
addXForwardedHeader(headers, HttpHeaderNames.X_FORWARDED_PORT, Integer.toString(request.getPort()));
addXForwardedHeader(headers, HttpHeaderNames.X_FORWARDED_PROTO, request.getScheme());
addXForwardedHeader(headers, HttpHeaderNames.X_FORWARDED_FOR, request.getClientIp());
}
Aggregations