use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class HttpRequestMessageImplTest method testGetOriginalPort.
@Test
public void testGetOriginalPort() {
HttpQueryParams queryParams = new HttpQueryParams();
Headers headers = new Headers();
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals(7002, request.getOriginalPort());
headers = new Headers();
headers.add("Host", "blah.netflix.com");
headers.add("X-Forwarded-Port", "443");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals(443, request.getOriginalPort());
headers = new Headers();
headers.add("Host", "blah.netflix.com:443");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals(443, request.getOriginalPort());
headers = new Headers();
headers.add("Host", "127.0.0.2:443");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals(443, request.getOriginalPort());
headers = new Headers();
headers.add("Host", "127.0.0.2");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals(7002, request.getOriginalPort());
headers = new Headers();
headers.add("Host", "[::2]:443");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals(443, request.getOriginalPort());
headers = new Headers();
headers.add("Host", "[::2]");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals(7002, request.getOriginalPort());
headers = new Headers();
headers.add("Host", "blah.netflix.com:443");
headers.add("X-Forwarded-Port", "7005");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals(7005, request.getOriginalPort());
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class HttpUtilsTest method getBodySizeIfKnown_returnsContentLengthValue.
@Test
public void getBodySizeIfKnown_returnsContentLengthValue() {
SessionContext context = new SessionContext();
Headers headers = new Headers();
headers.add(com.netflix.zuul.message.http.HttpHeaderNames.CONTENT_LENGTH, "23450");
ZuulMessage msg = new ZuulMessageImpl(context, headers);
assertThat(HttpUtils.getBodySizeIfKnown(msg)).isEqualTo(Integer.valueOf(23450));
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class HttpUtilsTest method getBodySizeIfKnown_returnsNull.
@Test
public void getBodySizeIfKnown_returnsNull() {
SessionContext context = new SessionContext();
Headers headers = new Headers();
ZuulMessage msg = new ZuulMessageImpl(context, headers);
assertThat(HttpUtils.getBodySizeIfKnown(msg)).isNull();
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class BaseZuulFilterRunner method recordFilterCompletion.
protected void recordFilterCompletion(final ExecutionStatus status, final ZuulFilter<I, O> filter, long startTime, final ZuulMessage zuulMesg, final ZuulMessage startSnapshot) {
final SessionContext zuulCtx = zuulMesg.getContext();
final long execTimeNs = System.nanoTime() - startTime;
final long execTimeMs = execTimeNs / 1_000_000L;
if (execTimeMs >= FILTER_EXCESSIVE_EXEC_TIME.get()) {
registry.timer(filterExcessiveTimerId.withTag("id", filter.filterName()).withTag("status", status.name())).record(execTimeMs, TimeUnit.MILLISECONDS);
}
// Record the execution summary in context.
switch(status) {
case FAILED:
if (logger.isDebugEnabled()) {
zuulCtx.addFilterExecutionSummary(filter.filterName(), FAILED.name(), execTimeMs);
}
break;
case SUCCESS:
if (logger.isDebugEnabled()) {
zuulCtx.addFilterExecutionSummary(filter.filterName(), SUCCESS.name(), execTimeMs);
}
if (startSnapshot != null) {
// debugRouting == true
Debug.addRoutingDebug(zuulCtx, "Filter {" + filter.filterName() + " TYPE:" + filter.filterType().toString() + " ORDER:" + filter.filterOrder() + "} Execution time = " + execTimeMs + "ms");
Debug.compareContextState(filter.filterName(), zuulCtx, startSnapshot.getContext());
}
break;
default:
break;
}
logger.debug("Filter {} completed with status {}, UUID {}", filter.filterName(), status.name(), zuulMesg.getContext().getUUID());
// Notify configured listener.
usageNotifier.notify(filter, status);
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class BaseZuulFilterRunner method recordFilterError.
protected void recordFilterError(final I inMesg, final ZuulFilter<I, O> filter, final Throwable t) {
// Add a log statement for this exception.
final String errorMsg = "Filter Exception: filter=" + filter.filterName() + ", request-info=" + inMesg.getInfoForLogging() + ", msg=" + String.valueOf(t.getMessage());
if (t instanceof ZuulException && !((ZuulException) t).shouldLogAsError()) {
logger.warn(errorMsg);
} else {
logger.error(errorMsg, t);
}
// Store this filter error for possible future use. But we still continue with next filter in the chain.
final SessionContext zuulCtx = inMesg.getContext();
zuulCtx.getFilterErrors().add(new FilterError(filter.filterName(), filter.filterType().toString(), t));
if (zuulCtx.debugRouting()) {
Debug.addRoutingDebug(zuulCtx, "Running Filter failed " + filter.filterName() + " type:" + filter.filterType() + " order:" + filter.filterOrder() + " " + t.getMessage());
}
}
Aggregations