gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] branch master updated (386b21da -> 0a4537e8)


From: gnunet
Subject: [libmicrohttpd] branch master updated (386b21da -> 0a4537e8)
Date: Sun, 13 Jun 2021 10:55:31 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 386b21da test_tls_options: multiple fixes
     new c7a0cf28 Corrected naming enum MHD_HTTP_version -> enum 
MHD_HTTP_Version
     new d4a6985d uncrustify.cfg: updated
     new 8391cfa2 connection.c: added detection of standard HTTP methods
     new 0a4537e8 connection.c: fixed wrong caseless HTTP method comparison

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 contrib/uncrustify.cfg      |  3 +++
 src/microhttpd/connection.c | 66 ++++++++++++++++++++++++++++++++++++++++-----
 src/microhttpd/internal.h   | 58 +++++++++++++++++++++++++++++++++++++--
 3 files changed, 119 insertions(+), 8 deletions(-)

diff --git a/contrib/uncrustify.cfg b/contrib/uncrustify.cfg
index 72520189..c751b42a 100644
--- a/contrib/uncrustify.cfg
+++ b/contrib/uncrustify.cfg
@@ -75,6 +75,9 @@ sp_before_sparen = add
 sp_inside_fparen = remove
 sp_inside_sparen = remove
 
+# Add or remove space around compare operator '<', '>', '==', etc
+sp_compare                                = force    # ignore/add/remove/force
+
 # add space before function call and decl: "foo (x)"
 sp_func_call_paren = add
 sp_func_proto_paren = add
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 7410949c..3d98f917 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -1491,9 +1491,7 @@ build_header_response (struct MHD_Connection *connection)
           MHD_get_response_header (response,
                                    MHD_HTTP_HEADER_CONTENT_LENGTH)) &&
          (may_add_content_length) &&
-         ( (NULL == connection->method) ||
-           (! MHD_str_equal_caseless_ (connection->method,
-                                       MHD_HTTP_METHOD_CONNECT)) ) )
+         (MHD_HTTP_MTHD_CONNECT != connection->http_mthd) )
     {
       /*
         Here we add a content-length if one is missing; however,
@@ -2214,6 +2212,58 @@ parse_http_version (struct MHD_Connection *connection,
 }
 
 
+/**
+ * Detect standard HTTP request method
+ *
+ * @param connection the connection
+ * @param method the pointer to HTTP request method string
+ * @param len the length of @a method in bytes
+ * @return #MHD_YES if HTTP method is valid string,
+ *         #MHD_NO if HTTP method string is not valid.
+ */
+static enum MHD_Result
+parse_http_std_method (struct MHD_Connection *connection,
+                       const char *method,
+                       size_t len)
+{
+  const char *const m = method; /**< short alias */
+  mhd_assert (NULL != m);
+
+  if (0 == len)
+    return MHD_NO;
+
+  if ((MHD_STATICSTR_LEN_ (MHD_HTTP_METHOD_GET) == len) &&
+      (0 == memcmp (m, MHD_HTTP_METHOD_GET, len)))
+    connection->http_mthd = MHD_HTTP_MTHD_GET;
+  else if ((MHD_STATICSTR_LEN_ (MHD_HTTP_METHOD_HEAD) == len) &&
+           (0 == memcmp (m, MHD_HTTP_METHOD_HEAD, len)))
+    connection->http_mthd = MHD_HTTP_MTHD_HEAD;
+  else if ((MHD_STATICSTR_LEN_ (MHD_HTTP_METHOD_POST) == len) &&
+           (0 == memcmp (m, MHD_HTTP_METHOD_POST, len)))
+    connection->http_mthd = MHD_HTTP_MTHD_POST;
+  else if ((MHD_STATICSTR_LEN_ (MHD_HTTP_METHOD_PUT) == len) &&
+           (0 == memcmp (m, MHD_HTTP_METHOD_PUT, len)))
+    connection->http_mthd = MHD_HTTP_MTHD_PUT;
+  else if ((MHD_STATICSTR_LEN_ (MHD_HTTP_METHOD_DELETE) == len) &&
+           (0 == memcmp (m, MHD_HTTP_METHOD_DELETE, len)))
+    connection->http_mthd = MHD_HTTP_MTHD_DELETE;
+  else if ((MHD_STATICSTR_LEN_ (MHD_HTTP_METHOD_CONNECT) == len) &&
+           (0 == memcmp (m, MHD_HTTP_METHOD_CONNECT, len)))
+    connection->http_mthd = MHD_HTTP_MTHD_CONNECT;
+  else if ((MHD_STATICSTR_LEN_ (MHD_HTTP_METHOD_OPTIONS) == len) &&
+           (0 == memcmp (m, MHD_HTTP_METHOD_OPTIONS, len)))
+    connection->http_mthd = MHD_HTTP_MTHD_OPTIONS;
+  else if ((MHD_STATICSTR_LEN_ (MHD_HTTP_METHOD_TRACE) == len) &&
+           (0 == memcmp (m, MHD_HTTP_METHOD_TRACE, len)))
+    connection->http_mthd = MHD_HTTP_MTHD_TRACE;
+  else
+    connection->http_mthd = MHD_HTTP_MTHD_OTHER;
+
+  /* Any method string with non-zero length is valid */
+  return MHD_YES;
+}
+
+
 /**
  * Parse the first line of the HTTP HEADER.
  *
@@ -2240,9 +2290,13 @@ parse_initial_message_line (struct MHD_Connection 
*connection,
     return MHD_NO;              /* serious error */
   uri[0] = '\0';
   connection->method = line;
+  if (MHD_NO == parse_http_std_method (connection, connection->method,
+                                       (size_t) (uri - line)))
+    return MHD_NO;
   uri++;
   /* Skip any spaces. Not required by standard but allow
      to be more tolerant. */
+  /* TODO: do not skip them in standard mode */
   while ( (' ' == uri[0]) &&
           ( (size_t) (uri - line) < line_len) )
     uri++;
@@ -2263,6 +2317,7 @@ parse_initial_message_line (struct MHD_Connection 
*connection,
     /* Search from back to accept malformed URI with space */
     http_version = line + line_len - 1;
     /* Skip any trailing spaces */
+    /* TODO: do not skip them in standard mode */
     while ( (' ' == http_version[0]) &&
             (http_version > uri) )
       http_version--;
@@ -3934,6 +3989,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       connection->current_chunk_size = 0;
       connection->current_chunk_offset = 0;
       connection->method = NULL;
+      connection->http_mthd = MHD_HTTP_MTHD_NO_METHOD;
       connection->url = NULL;
       connection->write_buffer = NULL;
       connection->write_buffer_size = 0;
@@ -4268,9 +4324,7 @@ MHD_queue_response (struct MHD_Connection *connection,
   /* FIXME: if 'is_pipe' is set, TLS is off, and we have *splice*, we could 
use splice()
      to avoid two user-space copies... */
 
-  if ( ( (NULL != connection->method) &&
-         (MHD_str_equal_caseless_ (connection->method,
-                                   MHD_HTTP_METHOD_HEAD)) ) ||
+  if ( (MHD_HTTP_MTHD_HEAD == connection->http_mthd) ||
        (MHD_HTTP_OK > status_code) ||
        (MHD_HTTP_NO_CONTENT == status_code) ||
        (MHD_HTTP_NOT_MODIFIED == status_code) )
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index aa4986a2..f4c9589e 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -732,7 +732,7 @@ enum MHD_ConnKeepAlive
   MHD_CONN_USE_KEEPALIVE = 1
 };
 
-enum MHD_HTTP_version
+enum MHD_HTTP_Version
 {
   /**
    * Not a HTTP protocol or HTTP version is invalid.
@@ -770,6 +770,55 @@ enum MHD_HTTP_version
   MHD_HTTP_VER_FUTURE = 100
 };
 
+/**
+ * The HTTP method.
+ *
+ * Only primary methods (specified in RFC7231) defined here.
+ */
+enum MHD_HTTP_Method
+{
+  /**
+   * No request string has been received yet
+   */
+  MHD_HTTP_MTHD_NO_METHOD = 0,
+  /**
+   * HTTP method GET
+   */
+  MHD_HTTP_MTHD_GET = 1,
+  /**
+   * HTTP method HEAD
+   */
+  MHD_HTTP_MTHD_HEAD = 2,
+  /**
+   * HTTP method POST
+   */
+  MHD_HTTP_MTHD_POST = 3,
+  /**
+   * HTTP method PUT
+   */
+  MHD_HTTP_MTHD_PUT = 4,
+  /**
+   * HTTP method DELETE
+   */
+  MHD_HTTP_MTHD_DELETE = 5,
+  /**
+   * HTTP method CONNECT
+   */
+  MHD_HTTP_MTHD_CONNECT = 6,
+  /**
+   * HTTP method OPTIONS
+   */
+  MHD_HTTP_MTHD_OPTIONS = 7,
+  /**
+   * HTTP method TRACE
+   */
+  MHD_HTTP_MTHD_TRACE = 8,
+  /**
+   * Other HTTP method. Check the string value.
+   */
+  MHD_HTTP_MTHD_OTHER = 1000
+};
+
 /**
  * Returns boolean 'true' if HTTP version is supported by MHD
  */
@@ -879,6 +928,11 @@ struct MHD_Connection
    */
   char *method;
 
+  /**
+   * The request method as enum.
+   */
+  enum MHD_HTTP_Method http_mthd;
+
   /**
    * Requested URL (everything after "GET" only).  Allocated
    * in pool.
@@ -894,7 +948,7 @@ struct MHD_Connection
   /**
    * HTTP protocol version as enum.
    */
-  enum MHD_HTTP_version http_ver;
+  enum MHD_HTTP_Version http_ver;
 
   /**
    * Close connection after sending response?

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]