| Author |
Message |
< Yaws mailing list ~ Bug in chunked encoding handling in revproxy |
| Guest |
Posted: Wed May 07, 2008 4:48 am |
|
|
|
Guest
|
Hello,
I've noticed that Yaws in reverse proxy mode handles HTTP chunked
encoding incorrectly, particularly, it sends an extra CRLF before the
last zero-length chunk (see
http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6.1). In
case if the http client is erlang's inets, this causes it to crash.
Here's the proposed patch:
== Cut here ==
--- yaws/src/yaws_revproxy.erl (revision 1236)
+++ yaws/src/yaws_revproxy.erl (working copy)
@@ -285,12 +285,7 @@
Hstr = headers_to_str(H = rewrite_headers(From, H0)),
yaws:gen_tcp_send(TS, [RStr, "\r\n", Hstr]),
From2 = sockmode(H, R, From),
- if
- From2#psock.mode == expectchunked ->
- true;
- true ->
- yaws:gen_tcp_send(TS,"\r\n")
- end,
+ yaws:gen_tcp_send(TS,"\r\n"),
ploop(From2, To, Pid);
closed ->
done
@@ -300,7 +295,7 @@
N = get_chunk_num(From#psock.s, get(ssl)),
if N == 0 ->
ok=eat_crnl(From#psock.s, get(ssl)),
- yaws:gen_tcp_send(TS,["\r\n0\r\n\r\n"]),
+ yaws:gen_tcp_send(TS,["0\r\n\r\n"]),
?Debug("SEND final 0 ",[]),
ploop_keepalive(From#psock{mode = expectheaders,
state = undefined},To, Pid);
@@ -311,19 +306,11 @@
chunk ->
CG = get_chunk(From#psock.s,From#psock.state, 0, get(ssl)),
SZ = From#psock.state,
- Data2 = ["\r\n", yaws:integer_to_hex(SZ),"\r\n", CG],
+ Data2 = [yaws:integer_to_hex(SZ),"\r\n", CG, "\r\n"],
yaws:gen_tcp_send(TS, Data2),
- ploop(From#psock{mode = expect_nl_before_chunked,
+ ok = eat_crnl(From#psock.s, get(ssl)),
+ ploop(From#psock{mode = expectchunked,
state = undefined}, To, Pid);
- expect_nl_before_chunked ->
- case yaws:do_recv(From#psock.s, 0, get(ssl)) of
- {ok, <<13,10>>} ->
- yaws:gen_tcp_send(TS,<<13,10>>),
- ploop(From#psock{mode = expectchunked,
- state = undefined}, To, Pid);
- _Other ->
- exit(normal)
- end;
len when From#psock.state == 0 ->
ploop_keepalive(From#psock{mode = expectheaders,
state = undefined},To, Pid);
== Cut here ==
Seems that chunked body handling is implemented with assumption that
CRLF comes before a chunk, not after, like said in HTTP 1.1 specs.
This makes a little difference but makes finding such discrepancies
trickier.
-
Oleg.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post received from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Wed May 07, 2008 8:49 am |
|
|
|
Guest
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|