reactphp / http

Event-driven, streaming HTTP client and server implementation for ReactPHP.
https://reactphp.org/http/
MIT License
740 stars 142 forks source link

MAX_CHUNK_HEADER_SIZE size increase #505

Closed ellisonpatterson closed 10 months ago

ellisonpatterson commented 11 months ago

I'm getting errors about the MAX_CHUNK_HEADER_SIZE being exceeded when making requests to a web service that is out of my control. EVENTUALLY it will go through (after retrying multiple times with ReactPHP HTTP client) but I'm wondering why the max chunk header size is set to 1024.

https://github.com/reactphp/http/blob/c6321978bfb82de979fe4dc28eb0c08bc34937ad/src/Io/ChunkedDecoder.php#L103

The comment says the header size shouldn't be bigger than 1024, but why?

Thank you!

clue commented 11 months ago

@ellisonpatterson Thank you for reporting, I'd like to understand this better before being able to tell whether this is a bug and how we could help with this specifically. Can you provide more insights what kind of server you're talking to and what problem you're seeing exactly?

The MAX_CHUNK_HEADER_SIZE constant is only used to define the maximum buffer size we use for reassembling chunks when using the chunked transfer encoding. Specifically, this is only used for the chunk header that commonly looks like 1000\r\n (6 bytes) or 0\r\n (3 bytes), so this does not directly limit the maximum size of the chunked payload data. Technically, this header may be followed by a chunk extension like 100;first=foo;next=bar\r\n (24 bytes), but this is used very(!) rarely in practice and would not be exposed by ReactPHP currently. As a consequence, the maximum buffer size of 1024 should be plenty and I have yet to see a case where this would be insufficient.

  chunked-body   = *chunk
                  last-chunk
                  trailer-section
                  CRLF

  chunk          = chunk-size [ chunk-ext ] CRLF
                   chunk-data CRLF
  chunk-size     = 1*HEXDIG
  last-chunk     = 1*("0") [ chunk-ext ] CRLF

  chunk-data     = 1*OCTET ; a sequence of chunk-size octets

https://datatracker.ietf.org/doc/html/rfc9112#section-7.1

ellisonpatterson commented 10 months ago

Yeah this was an issue on my end, I apologize!

SimonFrings commented 10 months ago

@ellisonpatterson thanks for the update. If you find the time, can you please give us an update what the solution for this was, so others with the same problem have the ability to find an answer in here :)

ellisonpatterson commented 7 months ago

I apologize about the delay, it was a misconfiguration on my end with some of my requests.