Skip to content

Commit 101cffc

Browse files
committed
Redirect using full part of the request URL after the host rarther than just the path part
1 parent e934f24 commit 101cffc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/charreada_handler.erl

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ proxy_host({undefined, Req}, _Timeout) ->
3939
ReplyReq;
4040
proxy_host({Host, Req}, Timeout) ->
4141
{Method, Req} = cowboy_req:method(Req),
42-
{Path, Req} = cowboy_req:path(Req),
42+
{HostUrl, Req} = cowboy_req:host_url(Req),
43+
{Url, Req} = cowboy_req:url(Req),
44+
UrlLen = byte_size(Url),
45+
PathUrl = binary:part(Url, {UrlLen, -(UrlLen - byte_size(HostUrl))}),
4346
{OrgHeaders, Req} = cowboy_req:headers(Req),
4447
NoHostHeaders = lists:keydelete(<<"host">>, 1, OrgHeaders),
4548
NoConnHeaders = lists:keydelete(<<"connection">>, 1, NoHostHeaders),
4649
{Cookies, CookiesReq} = cowboy_req:cookies(Req),
4750
BodyFun = {fun post_body/1, self()},
4851
Resp = charreada_config:redirect_request(
49-
Method, Host, Path, NoConnHeaders, Cookies, BodyFun, Timeout),
52+
Method, Host, PathUrl, NoConnHeaders, Cookies, BodyFun, Timeout),
5053
handle_redirect(Resp, CookiesReq, Timeout).
5154

5255
handle_redirect(ok, Req, Timeout) ->

0 commit comments

Comments
 (0)