View Issue Details

IDProjectCategoryView StatusLast Update
0001968libmicrohttpdexternal APIpublic2011-11-28 18:03
Reporterwillbryant Assigned ToChristian Grothoff  
PrioritynoneSeverityfeatureReproducibilityN/A
Status closedResolutionno change required 
Product Version0.9.17 
Target Version0.9.17Fixed in Version0.9.17 
Summary0001968: Add HTTP version to connection info API to allow CLF logging
DescriptionThe Common Log Format includes the HTTP version string, which MHD keeps track of but does not currently expose through the API (as far as I can see).

The attached patch implements this using the existing connection info mechanism.

It would also be very useful if the URL and HTTP method were available either in this API or in the MHD_OPTION_NOTIFY_COMPLETED callback arguments, because then the entire CLF log could be written from the information given to the MHD_OPTION_NOTIFY_COMPLETED function.

Would you be OK with me adding those to the connection info API? I see that as both better for backwards compatibility and more useful in general.
TagsNo tags attached.
Attached Files
0001-expose-the-request-s-HTTP-version-through-MHD_get_co.patch (3,920 bytes)   
From 2a53d68ccd8103b3589d47c498273828219cb9a6 Mon Sep 17 00:00:00 2001
From: Will Bryant <will.bryant@gmail.com>
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

Activities

Christian Grothoff

2011-11-28 18:03

manager   ~0004994

Dear Will, please look at 'version' in the central callback:

typedef int
  (*MHD_AccessHandlerCallback) (void *cls,
                                struct MHD_Connection * connection,
                                const char *url,
                                const char *method,
                                const char *version,
                                const char *upload_data,
                                size_t *upload_data_size,
                                void **con_cls);

Given this, I don't see a need to expose version *also* via the connection-info API.

Issue History

Date Modified Username Field Change
2011-11-27 12:56 willbryant New Issue
2011-11-27 12:56 willbryant File Added: 0001-expose-the-request-s-HTTP-version-through-MHD_get_co.patch
2011-11-28 18:03 Christian Grothoff Note Added: 0004994
2011-11-28 18:03 Christian Grothoff Assigned To => Christian Grothoff
2011-11-28 18:03 Christian Grothoff Priority normal => none
2011-11-28 18:03 Christian Grothoff Status new => closed
2011-11-28 18:03 Christian Grothoff Resolution open => no change required
2011-11-28 18:03 Christian Grothoff Fixed in Version => 0.9.17
2011-11-28 18:03 Christian Grothoff Target Version => 0.9.17
2013-05-06 12:52 Christian Grothoff Category API => libmicrohttpd API
2024-01-21 13:24 Christian Grothoff Category libmicrohttpd API => external API