|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
Handling of http chunked encodingHi all,
We had to make a slight modification to erlang's handling of chunked encoding to make it work with a system we have here. The problem is this: We're using http chunked encoding to implement a long term connection where status updates are periodically sent as http chunks. My understanding is that this is a bit of an abuse of the system (I didn't come up with it, I swear :)), but that it's also not an especially uncommon use. Each status update is a full chunk with the size and complete body. The problem is that the http library won't forward on a chunk to the client process until the size field for the following chunk has been received, due to it wanting to check if it's the last chunk (indicated by the next size field being 0). The net effect is that we can't extract a status update chunk until the next one arrives (which is some indeterminate time away). The attached patch makes a small modification to forward any full chunk received, regardless of whether the size field for the following chunk has been received yet. I'm not sure whether or not you'll want to include it (there may be a very good reason for it working the way it does, and by my understanding it's not technically breaking any rules as it currently works), but it doesn't seem to do any harm and gets clients valid data sooner. The patch is against R13B. Cheers, Bernard --- otp_src_R13B_orig/lib/inets/src/http_lib/http_chunk.erl 2009-03-12 23:31:42.000000000 +1100 +++ otp_src_R13B/lib/inets/src/http_lib/http_chunk.erl 2009-04-29 13:20:25.000000000 +1000 @@ -186,13 +186,6 @@ Info = {MaxBodySize, BodySoFar, AccLength, MaxHeaderSize, Stream}) when ChunkSize =< size(TotalChunk) -> case TotalChunk of - %% Potential last chunk - <<_:ChunkSize/binary, ?CR, ?LF, "0">> -> - {?MODULE, decode_data, [ChunkSize, TotalChunk, Info]}; - <<_:ChunkSize/binary, ?CR, ?LF, "0", ?CR>> -> - {?MODULE, decode_data, [ChunkSize, TotalChunk, Info]}; - <<_:ChunkSize/binary, ?CR, ?LF>> -> - {?MODULE, decode_data, [ChunkSize, TotalChunk, Info]}; %% Last chunk <<Data:ChunkSize/binary, ?CR, ?LF, "0", ";">> -> %% Note ignore_extensions will call decode_trailer/1 @@ -223,6 +216,9 @@ NewBody, integer_to_list(AccLength)); %% There are more chunks, so here we go agin... + <<Data:ChunkSize/binary, ?CR, ?LF>> -> + {NewBody, NewStream} = stream(<<BodySoFar/binary, Data/binary>>, Stream), + {?MODULE, decode_size, [<<>>, [], {MaxBodySize, NewBody, AccLength, MaxHeaderSize, NewStream}]}; <<Data:ChunkSize/binary, ?CR, ?LF, Rest/binary>> when (AccLength < MaxBodySize) or (MaxBodySize == nolimit) -> {NewBody, NewStream} = _______________________________________________ erlang-patches mailing list erlang-patches@... http://www.erlang.org/mailman/listinfo/erlang-patches |
| Free embeddable forum powered by Nabble | Forum Help |