maru / libmicrohttpd-http2

HTTP/2 support for libmicrohttpd
https://http2.s106.net/
Other
22 stars 6 forks source link

Sending data problem when MHD_OPTION_CONNECTION_MEMORY_LIMIT is set to default #72

Open IronBug opened 4 years ago

IronBug commented 4 years ago

I use libmicrohttpd_http2 in my program and I found a strange problem with sending data. It was ok with http/1.1 and failed with http/2. I traced it down and found that this piece of code blocks sending: src/microhttpd/http2/h2_callbacks.c:722

/* Check if there is enough space to write the DATA frame */
  if ((stream->c.suspended)
      || (left < 9 + length + padlen) /* 9 = frame header */ )
    {
      return NGHTTP2_ERR_WOULDBLOCK;
    }

The length of data block nghttp2 sends is defined by default value but header takes some space and the length checking if condition is always true for data blocks exceeding the default buffer size - 9. So with http/2 data sending hangs up. It works fine for http/1.1. So I think it's the problem of the header. The possible solution is to set MHD_OPTION_CONNECTION_MEMORY_LIMIT to 9 bytes larger than default. But it shouldn't fall with default values, anyway.