hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hiranya Jayathilaka <hiranya...@gmail.com>
Subject Re: Getting the Full Request URL from HTTP Core API
Date Mon, 27 Jun 2011 21:15:03 GMT
On Tue, Jun 28, 2011 at 1:12 AM, Oleg Kalnichevski <olegk@apache.org> wrote:

> 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.
>

Thanks Oleg. This is pretty much what I had in my mind as well. Just needed
to get it confirmed.

Thanks,
Hiranya


>
> ---
> 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
>
>


-- 
Hiranya Jayathilaka
Senior Software Engineer;
WSO2 Inc.;  http://wso2.org
E-mail: hiranya@wso2.com;  Mobile: +94 77 633 3491
Blog: http://techfeast-hiranya.blogspot.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message