Skip to content

Reading from request stream hangs when "Transfer-Encoding: chunked" is used #3147

@Mironenko

Description

@Mironenko

The minimal example of the request handler used in my application is as follows:

	class StreamBufferReadHandler: public HTTPRequestHandler
	{
	public:
		void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
		{
			auto streambuf = request.stream().rdbuf();

			char buffer[4096];
			streambuf->sgetn(buffer, sizeof(buffer));
			streambuf->sgetn(buffer, sizeof(buffer));

			response.send();
		}
	};

I.e. the following assertments are true:

  • std::ios::rdbuf is used to get the data from the stream;
  • getting data from std::ios::rdbuf may be requested after EOF was already hit once.

The code works properly when fixed-length request is received, but hangs with chunked-encoded one. Looks like the main problem is HTTPChunkedStreamBuf does not save EOF state inside, as HTTPFixedLengthStreamBuf does.

Is it a bug or is the behavior expected? May it be fixed?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions