View Issue Details

IDProjectCategoryView StatusLast Update
0007242libmicrohttpdHTTP 1.1 request pipeliningpublic2022-05-14 14:50
Reportergray Assigned To 
Status newResolutionopen 
Product Version0.9.75 
Summary0007242: Connection: close is always set in response
DescriptionLibmicrohttpd always sets "Connection: close" header in response to HTTP/1.1 requests. In my opinion, it is wrong, as HTTP 1.1 assumes keep-alive by defauit. Correct me if I'm wrong. The header is set to "close" because MHD_queue_response sets connection->discard_request to true in line 5261 of connection.c. Apparently, this tracks down to commit 78d0fb7b2. Before that, the "Connection:" header was set to "Keep-Alive", as expected.
Steps To ReproduceAttached is a trivial program implementing a HTTP server listening on port 8080. Compile and run it. From another console, run curl -v You will see "Connection: close" in response.

When compiled with libmicrohttpd prior to commit 78d0fb7b2, Keep-Alive" would be returned instead.
TagsNo tags attached.



2022-05-14 14:50


connclose.c (1,025 bytes)   
#include <microhttpd.h>
#include <signal.h>

static enum MHD_Result
httpd_handler (void *cls,
	       struct MHD_Connection *conn,
	       const char *url, const char *method,
	       const char *version,
	       const char *upload_data, size_t *upload_data_size,
	       void **con_cls)
  struct MHD_Response *response;
  enum MHD_Result ret;
  static char resp[] = "Response text";
  response = MHD_create_response_from_buffer (sizeof (resp) - 1, resp, MHD_RESPMEM_PERSISTENT);
  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/plain");
  ret = MHD_queue_response (conn, MHD_HTTP_OK, response);
  MHD_destroy_response (response);
  return ret;

main (int argc, char **argv)
  struct MHD_Daemon *mhd;
  int port = 8080;
  sigset_t sigs;
  int i;
			  NULL, NULL,
			  httpd_handler, NULL,

  sigfillset (&sigs);
  sigwait (&sigs, &i);
  MHD_stop_daemon (mhd);
  return 0;
connclose.c (1,025 bytes)   

Issue History

Date Modified Username Field Change
2022-05-14 14:50 gray New Issue
2022-05-14 14:50 gray File Added: connclose.c