hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPCLIENT-1496) HttpRequestInterceptors do not have easy access to the scheme, host or port of the request.
Date Wed, 16 Apr 2014 12:35:14 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13970728#comment-13970728

Oleg Kalnichevski commented on HTTPCLIENT-1496:


The host, port and scheme of the current request can be obtained from the execution request
as the HttpClientContext#HTTP_TARGET_HOST attribute. Should not that be sufficient?

CloseableHttpClient hc = HttpClients.custom()
        .addInterceptorFirst(new HttpRequestInterceptor() {
            public void process(
                    final HttpRequest request,
                    final HttpContext context) throws HttpException, IOException {
                HttpHost target = (HttpHost) context.getAttribute(

CloseableHttpResponse response = hc.execute(new HttpGet("http://google.com/"));
try {

} finally {

> HttpRequestInterceptors do not have easy access to the scheme, host or port of the request.
> -------------------------------------------------------------------------------------------
>                 Key: HTTPCLIENT-1496
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1496
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient
>    Affects Versions: 4.3.3
>            Reporter: Matt Inger
> When writing an HttpRequestInterceptor, there are some cases where it is necessary to
have access to the absolute URL of the request being intercepted.  This is required in order
to get data like the scheme (http/https) and the host name in some situations.
> However, due to the nature of how the requests are wrapped in HttpClient 4.3, all instances
of HttpUriRequest are wrapped with an HttpRequestWrapper, and converted into a relative request.
> At that point, you cannot retrieve the scheme, hostname or port of the original request
without casting to an HttpRequestWrapper, and unwrapping the original request from it.
> It would be helpful if there was a way to easily retrieve this information from the HttpRequestWrapper.
 Even more helpful would be some mechanism (a new method on HttpRequest perhaps) to retrieve
all these pieces of data without having an instanceof and a cast.

This message was sent by Atlassian JIRA

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org

View raw message