I don't whether this is exactly what you want or whether there is a
better way of doing this:
Host = mochiweb_headers:get_value("host", Headers),
URL = "http://" ++ Host ++ "/" ++ RelPath ++ "/"
HTH,
Ben
Thanks, someone on couchdb channel also give me link to have Host when
no Host header is provided. Here is the extracted method from couchdb
:
absolute_uri(Req, Path) ->
Host = case Req:get_header_value("Host") of
undefined ->
{ok, {Address, Port}} = inet:sockname(Req:get(socket)),
inet_parse:ntoa(Address) ++ ":" ++ integer_to_list(Port);
Value -> Value
end,
"http://" ++ Host ++ Path.
Maybe it could be provided by mochiweb api anyway ?
- benoît
On 18 Jul 2009, at 07:03, Benoit Chesneau <bche...@gmail.com> wrote:
> Thanks, someone on couchdb channel also give me link to have Host when
> no Host header is provided. Here is the extracted method from couchdb
> :
>
> absolute_uri(Req, Path) ->
> Host = case Req:get_header_value("Host") of
> undefined ->
> {ok, {Address, Port}} = inet:sockname(Req:get(socket)),
> inet_parse:ntoa(Address) ++ ":" ++ integer_to_list(Port);
> Value -> Value
> end,
> "http://" ++ Host ++ Path.
>
> Maybe it could be provided by mochiweb api anyway ?
There's probably one or two ways to do this, depending on the calling
context.
If you a change to the API, I would have thought a patch is the best
way to go.
Ben