From 2a53d68ccd8103b3589d47c498273828219cb9a6 Mon Sep 17 00:00:00 2001 From: Will Bryant Date: Mon, 28 Nov 2011 00:55:22 +1300 Subject: [PATCH] expose the request's HTTP version through MHD_get_connection_info --- doc/microhttpd.texi | 3 +++ src/daemon/connection.c | 2 ++ src/include/microhttpd.h | 13 ++++++++++++- src/testcurl/https/mhds_session_info_test.c | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 1 deletions(-) diff --git a/doc/microhttpd.texi b/doc/microhttpd.texi index d018f39..1ecb456 100644 --- a/doc/microhttpd.texi +++ b/doc/microhttpd.texi @@ -2060,6 +2060,9 @@ Takes no extra arguments. Allows finding out the TLS/SSL protocol used (HTTPS connections only). NULL is returned for non-HTTPS connections. +@item MHD_CONNECTION_INFO_HTTP_VERSION, +Takes no extra arguments. The HTTP version string given in the client request. + @item MHD_CONNECTION_INFO_CLIENT_ADDRESS Returns information about the address of the client. Returns essentially a @code{struct sockaddr **} (since the API returns diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 70e1ad9..2f0edbd 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c @@ -2407,6 +2407,8 @@ MHD_get_connection_info (struct MHD_Connection *connection, return (const union MHD_ConnectionInfo *) &connection->addr; case MHD_CONNECTION_INFO_DAEMON: return (const union MHD_ConnectionInfo *) &connection->daemon; + case MHD_CONNECTION_INFO_HTTP_VERSION: + return (const union MHD_ConnectionInfo *) &connection->version; default: return NULL; }; diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h index 4904dcb..bd27ecc 100644 --- a/src/include/microhttpd.h +++ b/src/include/microhttpd.h @@ -720,12 +720,18 @@ enum MHD_ConnectionInfoType MHD_CONNECTION_INFO_CIPHER_ALGO, /** - * + * What TLS/SSL protocol is being used. * Takes no extra arguments. */ MHD_CONNECTION_INFO_PROTOCOL, /** + * What HTTP version was used for the request. + * Takes no extra arguments. + */ + MHD_CONNECTION_INFO_HTTP_VERSION, + + /** * Obtain IP address of the client. Takes no extra arguments. * Returns essentially a "struct sockaddr **" (since the API returns * a "union MHD_ConnectionInfo *" and that union contains a "struct @@ -1628,6 +1634,11 @@ union MHD_ConnectionInfo void * /* gnutls_x509_crt_t */ client_cert; /** + * HTTP version for the request. + */ + const char* version; + + /** * Address information for the client. */ struct sockaddr *client_addr; diff --git a/src/testcurl/https/mhds_session_info_test.c b/src/testcurl/https/mhds_session_info_test.c index 4f8c67d..2f116f4 100644 --- a/src/testcurl/https/mhds_session_info_test.c +++ b/src/testcurl/https/mhds_session_info_test.c @@ -36,6 +36,8 @@ extern const char srv_self_signed_cert_pem[]; struct MHD_Daemon *d; +#define EXPECTED_HTTP_VERSION "HTTP/1.1" + /* * HTTP access handler call back * used to query negotiated security parameters @@ -48,6 +50,7 @@ query_session_ahc (void *cls, struct MHD_Connection *connection, { struct MHD_Response *response; int ret; + const char* ret_s; if (NULL == *ptr) { @@ -77,6 +80,17 @@ query_session_ahc (void *cls, struct MHD_Connection *connection, ret); return -1; } + + if (strcmp(EXPECTED_HTTP_VERSION, + (ret_s = MHD_get_connection_info + (connection, + MHD_CONNECTION_INFO_HTTP_VERSION)->version)) != 0) + { + fprintf (stderr, "Error: expected HTTP version mismatch (wanted %s, got %s)\n", + EXPECTED_HTTP_VERSION, + ret_s); + return -1; + } response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE), (void *) EMPTY_PAGE, -- 1.7.4.4