Сопоставление перехватчика ответа Apache HttpClient с запросом

Apache HttpClient имеет интерфейс HttpResponseInterceptor с этим методом.

void process(HttpResponse response, HttpContext context)

Как получить экземпляр HttpRequest, который привел к этому экземпляру HttpResponse?

HttpClients.custom()
            .addInterceptorLast((HttpResponseInterceptor)(response, context) -> {
                // how to get matching request?
            })
            .build();

person Frank    schedule 06.08.2019    source источник


Ответы (1)


Фактическое сообщение HTTP-запроса, а также другие детали выполнения запроса можно получить из контекста выполнения:

HttpClients.custom()
        .addInterceptorLast((HttpResponseInterceptor) (response, context) -> {
            final HttpClientContext clientContext = HttpClientContext.adapt(context);
            final HttpRequest request = clientContext.getRequest();
        })
        .build();
person ok2c    schedule 06.08.2019