hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Getting the Full Request URL from HTTP Core API
Date Mon, 27 Jun 2011 19:42:26 GMT
On Mon, 2011-06-27 at 22:17 +0530, Hiranya Jayathilaka wrote:
> Hi Devs,
> 
> Is there a way to get the actual URL requested by the client when receiving
> a message through HTTP Core API? For instance if we are implementing a web
> server using HTTP Core, and the user types in the URL
> http://test.com/1/2/3on his browser, is there a way to get the full
> URL including the
> test.com part in the server side code?
> 
> Thanks

Hiranya

Something like that should the trick, I think.

---
public URI getRequestURI(HttpRequest request) throws Exception {
    String path = request.getRequestLine().getUri();
    String host;
    Header h = request.getFirstHeader(HTTP.TARGET_HOST);
    if (h != null) {
        host = h.getValue();
    } else {
        host = InetAddress.getLocalHost().getCanonicalHostName();
    }
    return new URI("http", host, path, null);
}
---
Oleg



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


Mime
View raw message