private void update(HttpLogEntry entry, Throwable t) { boolean canRetry = (t instanceof ConnectException || t instanceof ReadTimeoutException); entry.mark("received-error").withException(t).withCanRetry(canRetry); }
private static void update(HttpLogEntry entry, HttpClientResponse<ByteBuf> res) { int code = res.getStatus().code(); boolean canRetry = (code == 429 || code >= 500); entry.mark("received-response") .withStatusCode(code) .withStatusReason(res.getStatus().reasonPhrase()) .withResponseContentLength(res.getHeaders().getContentLength(-1)) .withCanRetry(canRetry); for (Map.Entry<String, String> h : res.getHeaders().entries()) { entry.withResponseHeader(h.getKey(), h.getValue()); } }
/** * Execute an HTTP request. * * @param context * Context associated with the request. * @return * Observable with the response of the request. */ Observable<HttpClientResponse<ByteBuf>> execute(final RequestContext context) { final HttpLogEntry entry = context.entry(); final HttpClient<ByteBuf, ByteBuf> client = getClient(context); entry.mark("start"); entry.withRemoteAddr(context.server().host()); entry.withRemotePort(context.server().port()); return client.submit(context.request()) .doOnNext(new Action1<HttpClientResponse<ByteBuf>>() { @Override public void call(HttpClientResponse<ByteBuf> res) { update(entry, res); HttpLogEntry.logClientRequest(entry); } }) .doOnError(new Action1<Throwable>() { @Override public void call(Throwable throwable) { update(entry, throwable); HttpLogEntry.logClientRequest(entry); } }) .doOnTerminate(Actions.empty()); }