gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (bb33e458 -> 9a18a4f8)


From: gnunet
Subject: [libmicrohttpd] branch master updated (bb33e458 -> 9a18a4f8)
Date: Tue, 09 Aug 2022 20:27:11 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from bb33e458 -typo
     new 93ef4701 Internal refactoring: moved all request-related members to 
separate structure
     new 82d86475 Internal refactoring: moved all reply-related members to 
separate structure
     new 6bf4168d gen_auth: added support for two authorization headers in 
request
     new 20001736 test_auth_parse: added testing of 'userhash' parameter parsing
     new 228ddbd1 digestauth: limit nonce-count to uint32_t
     new 9a18a4f8 test_auth_parse: added check of two auths types parsing in 
one request

The 6 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:
 src/microhttpd/basicauth.c                |   23 +-
 src/microhttpd/connection.c               |  622 +++++++------
 src/microhttpd/daemon.c                   |   24 +-
 src/microhttpd/digestauth.c               |   54 +-
 src/microhttpd/gen_auth.c                 |  398 +++++----
 src/microhttpd/gen_auth.h                 |   68 +-
 src/microhttpd/internal.h                 |  380 ++++----
 src/microhttpd/mhd_send.c                 |   29 +-
 src/microhttpd/response.c                 |    2 +-
 src/microhttpd/test_auth_parse.c          | 1340 +++++++++++++++++------------
 src/microhttpd/test_postprocessor.c       |   20 +-
 src/microhttpd/test_postprocessor_amp.c   |    2 +-
 src/microhttpd/test_postprocessor_large.c |    2 +-
 13 files changed, 1580 insertions(+), 1384 deletions(-)

diff --git a/src/microhttpd/basicauth.c b/src/microhttpd/basicauth.c
index 8c3adbdb..07b124f1 100644
--- a/src/microhttpd/basicauth.c
+++ b/src/microhttpd/basicauth.c
@@ -33,27 +33,6 @@
 #include "mhd_str.h"
 
 
-/**
- * Get request's Basic Authorisation parameters.
- * @param connection the connection to process
- * @return pointer to request Basic Authorisation parameters structure if
- *         request has such header (allocated in connection's pool),
- *         NULL otherwise.
- */
-static const struct MHD_RqBAuth *
-get_rq_bauth_params (struct MHD_Connection *connection)
-{
-  const struct MHD_AuthRqHeader *rq_params;
-
-  rq_params = MHD_get_auth_rq_params_ (connection);
-  if ( (NULL == rq_params) ||
-       (MHD_AUTHTYPE_BASIC != rq_params->auth_type) )
-    return NULL;
-
-  return rq_params->params.bauth;
-}
-
-
 /**
  * Get the username and password from the Basic Authorisation header
  * sent by the client
@@ -73,7 +52,7 @@ MHD_basic_auth_get_username_password3 (struct MHD_Connection 
*connection)
   size_t decoded_max_len;
   struct MHD_BasicAuthInfo *ret;
 
-  params = get_rq_bauth_params (connection);
+  params = MHD_get_rq_bauth_params_ (connection);
 
   if (NULL == params)
     return NULL;
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 9068ee08..f33f9a9f 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -392,7 +392,7 @@ MHD_get_connection_values (struct MHD_Connection 
*connection,
   if (NULL == connection)
     return -1;
   ret = 0;
-  for (pos = connection->headers_received; NULL != pos; pos = pos->next)
+  for (pos = connection->rq.headers_received; NULL != pos; pos = pos->next)
     if (0 != (pos->kind & kind))
     {
       ret++;
@@ -433,13 +433,13 @@ MHD_get_connection_values_n (struct MHD_Connection 
*connection,
   ret = 0;
 
   if (NULL == iterator)
-    for (pos = connection->headers_received; NULL != pos; pos = pos->next)
+    for (pos = connection->rq.headers_received; NULL != pos; pos = pos->next)
     {
       if (0 != (kind & pos->kind))
         ret++;
     }
   else
-    for (pos = connection->headers_received; NULL != pos; pos = pos->next)
+    for (pos = connection->rq.headers_received; NULL != pos; pos = pos->next)
       if (0 != (kind & pos->kind))
       {
         ret++;
@@ -493,15 +493,15 @@ MHD_set_connection_value_n_nocheck_ (struct 
MHD_Connection *connection,
   pos->kind = kind;
   pos->next = NULL;
   /* append 'pos' to the linked list of headers */
-  if (NULL == connection->headers_received_tail)
+  if (NULL == connection->rq.headers_received_tail)
   {
-    connection->headers_received = pos;
-    connection->headers_received_tail = pos;
+    connection->rq.headers_received = pos;
+    connection->rq.headers_received_tail = pos;
   }
   else
   {
-    connection->headers_received_tail->next = pos;
-    connection->headers_received_tail = pos;
+    connection->rq.headers_received_tail->next = pos;
+    connection->rq.headers_received_tail = pos;
   }
   return MHD_YES;
 }
@@ -660,7 +660,7 @@ MHD_lookup_connection_value_n (struct MHD_Connection 
*connection,
 
   if (NULL == key)
   {
-    for (pos = connection->headers_received; NULL != pos; pos = pos->next)
+    for (pos = connection->rq.headers_received; NULL != pos; pos = pos->next)
     {
       if ( (0 != (kind & pos->kind)) &&
            (NULL == pos->header) )
@@ -669,7 +669,7 @@ MHD_lookup_connection_value_n (struct MHD_Connection 
*connection,
   }
   else
   {
-    for (pos = connection->headers_received; NULL != pos; pos = pos->next)
+    for (pos = connection->rq.headers_received; NULL != pos; pos = pos->next)
     {
       if ( (0 != (kind & pos->kind)) &&
            (key_size == pos->header_size) &&
@@ -722,7 +722,7 @@ MHD_lookup_header_token_ci (const struct MHD_Connection 
*connection,
       (NULL == token) || (0 == token[0]))
     return false;
 
-  for (pos = connection->headers_received; NULL != pos; pos = pos->next)
+  for (pos = connection->rq.headers_received; NULL != pos; pos = pos->next)
   {
     if ((0 != (pos->kind & MHD_HEADER_KIND)) &&
         (header_len == pos->header_size) &&
@@ -765,7 +765,7 @@ need_100_continue (struct MHD_Connection *connection)
 {
   const char *expect;
 
-  return (MHD_IS_HTTP_VER_1_1_COMPAT (connection->http_ver) &&
+  return (MHD_IS_HTTP_VER_1_1_COMPAT (connection->rq.http_ver) &&
           (MHD_NO != MHD_lookup_connection_value_n (connection,
                                                     MHD_HEADER_KIND,
                                                     MHD_HTTP_HEADER_EXPECT,
@@ -827,22 +827,22 @@ MHD_connection_close_ (struct MHD_Connection *connection,
                        enum MHD_RequestTerminationCode termination_code)
 {
   struct MHD_Daemon *daemon = connection->daemon;
-  struct MHD_Response *resp = connection->response;
+  struct MHD_Response *resp = connection->rp.response;
 
 #ifdef MHD_USE_THREADS
   mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \
                MHD_thread_ID_match_current_ (connection->pid) );
 #endif /* MHD_USE_THREADS */
   if ( (NULL != daemon->notify_completed) &&
-       (connection->client_aware) )
+       (connection->rq.client_aware) )
     daemon->notify_completed (daemon->notify_completed_cls,
                               connection,
-                              &connection->client_context,
+                              &connection->rq.client_context,
                               termination_code);
-  connection->client_aware = false;
+  connection->rq.client_aware = false;
   if (NULL != resp)
   {
-    connection->response = NULL;
+    connection->rp.response = NULL;
     MHD_destroy_response (resp);
   }
   if (NULL != connection->pool)
@@ -977,9 +977,9 @@ static void
 connection_close_error_check (struct MHD_Connection *connection,
                               const char *emsg)
 {
-  if ( (NULL != connection->response) &&
-       (400 <= connection->responseCode) &&
-       (NULL == connection->response->crc) && /* Static response only! */
+  if ( (NULL != connection->rp.response) &&
+       (400 <= connection->rp.responseCode) &&
+       (NULL == connection->rp.response->crc) && /* Static response only! */
        (connection->stop_with_error) &&
        (MHD_CONNECTION_HEADERS_SENDING == connection->state) )
     return; /* An error response was already queued */
@@ -1019,23 +1019,23 @@ try_ready_normal_body (struct MHD_Connection 
*connection)
   ssize_t ret;
   struct MHD_Response *response;
 
-  response = connection->response;
-  mhd_assert (connection->rp_props.send_reply_body);
+  response = connection->rp.response;
+  mhd_assert (connection->rp.props.send_reply_body);
 
   if ( (0 == response->total_size) ||
                      /* TODO: replace the next check with assert */
-       (connection->response_write_position == response->total_size) )
+       (connection->rp.rsp_write_position == response->total_size) )
     return MHD_YES;  /* 0-byte response is always ready */
   if (NULL != response->data_iov)
   {
     size_t copy_size;
 
-    if (NULL != connection->resp_iov.iov)
+    if (NULL != connection->rp.resp_iov.iov)
       return MHD_YES;
     copy_size = response->data_iovcnt * sizeof(MHD_iovec_);
-    connection->resp_iov.iov = MHD_connection_alloc_memory_ (connection,
-                                                             copy_size);
-    if (NULL == connection->resp_iov.iov)
+    connection->rp.resp_iov.iov = MHD_connection_alloc_memory_ (connection,
+                                                                copy_size);
+    if (NULL == connection->rp.resp_iov.iov)
     {
       MHD_mutex_unlock_chk_ (&response->mutex);
       /* not enough memory */
@@ -1043,22 +1043,22 @@ try_ready_normal_body (struct MHD_Connection 
*connection)
                               _ ("Closing connection (out of memory)."));
       return MHD_NO;
     }
-    memcpy (connection->resp_iov.iov,
+    memcpy (connection->rp.resp_iov.iov,
             response->data_iov,
             copy_size);
-    connection->resp_iov.cnt = response->data_iovcnt;
-    connection->resp_iov.sent = 0;
+    connection->rp.resp_iov.cnt = response->data_iovcnt;
+    connection->rp.resp_iov.sent = 0;
     return MHD_YES;
   }
   if (NULL == response->crc)
     return MHD_YES;
   if ( (response->data_start <=
-        connection->response_write_position) &&
+        connection->rp.rsp_write_position) &&
        (response->data_size + response->data_start >
-        connection->response_write_position) )
+        connection->rp.rsp_write_position) )
     return MHD_YES; /* response already ready */
 #if defined(_MHD_HAVE_SENDFILE)
-  if (MHD_resp_sender_sendfile == connection->resp_sender)
+  if (MHD_resp_sender_sendfile == connection->rp.resp_sender)
   {
     /* will use sendfile, no need to bother response crc */
     return MHD_YES;
@@ -1066,17 +1066,17 @@ try_ready_normal_body (struct MHD_Connection 
*connection)
 #endif /* _MHD_HAVE_SENDFILE */
 
   ret = response->crc (response->crc_cls,
-                       connection->response_write_position,
+                       connection->rp.rsp_write_position,
                        (char *) response->data,
                        (size_t) MHD_MIN ((uint64_t) response->data_buffer_size,
                                          response->total_size
-                                         - 
connection->response_write_position));
+                                         - connection->rp.rsp_write_position));
   if (0 > ret)
   {
     /* either error or http 1.0 transfer, close socket! */
     /* TODO: do not update total size, check whether response
      * was really with unknown size */
-    response->total_size = connection->response_write_position;
+    response->total_size = connection->rp.rsp_write_position;
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
     MHD_mutex_unlock_chk_ (&response->mutex);
 #endif
@@ -1089,7 +1089,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
                                 "Closing connection (application reported 
error generating data)."));
     return MHD_NO;
   }
-  response->data_start = connection->response_write_position;
+  response->data_start = connection->rp.rsp_write_position;
   response->data_size = (size_t) ret;
   if (0 == ret)
   {
@@ -1131,7 +1131,7 @@ try_ready_chunked_body (struct MHD_Connection *connection,
   uint64_t left_to_send;
   size_t size_to_fill;
 
-  response = connection->response;
+  response = connection->rp.response;
   mhd_assert (NULL != response->crc || NULL != response->data);
 
   mhd_assert (0 == connection->write_buffer_append_offset);
@@ -1167,7 +1167,8 @@ try_ready_chunked_body (struct MHD_Connection *connection,
   if (MHD_SIZE_UNKNOWN == response->total_size)
     left_to_send = MHD_SIZE_UNKNOWN;
   else
-    left_to_send = response->total_size - connection->response_write_position;
+    left_to_send = response->total_size
+                   - connection->rp.rsp_write_position;
 
   size_to_fill = connection->write_buffer_size - max_chunk_overhead;
   /* Limit size for the callback to the max usable size */
@@ -1180,14 +1181,15 @@ try_ready_chunked_body (struct MHD_Connection 
*connection,
     /* nothing to send, don't bother calling crc */
     ret = MHD_CONTENT_READER_END_OF_STREAM;
   else if ( (response->data_start <=
-             connection->response_write_position) &&
+             connection->rp.rsp_write_position) &&
             (response->data_start + response->data_size >
-             connection->response_write_position) )
+             connection->rp.rsp_write_position) )
   {
-    /* difference between response_write_position and data_start is less
+    /* difference between rsp_write_position and data_start is less
        than data_size which is size_t type, no need to check for overflow */
     const size_t data_write_offset
-      = (size_t) (connection->response_write_position - response->data_start);
+      = (size_t) (connection->rp.rsp_write_position
+                  - response->data_start);
     /* buffer already ready, use what is there for the chunk */
     mhd_assert (SSIZE_MAX >= (response->data_size - data_write_offset));
     mhd_assert (response->data_size >= data_write_offset);
@@ -1210,7 +1212,7 @@ try_ready_chunked_body (struct MHD_Connection *connection,
       return MHD_NO;
     }
     ret = response->crc (response->crc_cls,
-                         connection->response_write_position,
+                         connection->rp.rsp_write_position,
                          &connection->write_buffer[max_chunk_hdr_len],
                          size_to_fill);
   }
@@ -1218,7 +1220,7 @@ try_ready_chunked_body (struct MHD_Connection *connection,
   {
     /* error, close socket! */
     /* TODO: remove update of the response size */
-    response->total_size = connection->response_write_position;
+    response->total_size = connection->rp.rsp_write_position;
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
     MHD_mutex_unlock_chk_ (&response->mutex);
 #endif
@@ -1231,7 +1233,7 @@ try_ready_chunked_body (struct MHD_Connection *connection,
   {
     *p_finished = true;
     /* TODO: remove update of the response size */
-    response->total_size = connection->response_write_position;
+    response->total_size = connection->rp.rsp_write_position;
     return MHD_YES;
   }
   if (0 == ret)
@@ -1266,7 +1268,7 @@ try_ready_chunked_body (struct MHD_Connection *connection,
   connection->write_buffer[max_chunk_hdr_len - 1] = '\n';
   connection->write_buffer[max_chunk_hdr_len + (size_t) ret] = '\r';
   connection->write_buffer[max_chunk_hdr_len + (size_t) ret + 1] = '\n';
-  connection->response_write_position += (size_t) ret;
+  connection->rp.rsp_write_position += (size_t) ret;
   connection->write_buffer_append_offset = max_chunk_hdr_len + (size_t) ret + 
2;
   return MHD_YES;
 }
@@ -1298,7 +1300,7 @@ static enum MHD_ConnKeepAlive
 keepalive_possible (struct MHD_Connection *connection)
 {
   struct MHD_Connection *const c = connection; /**< a short alias */
-  struct MHD_Response *const r = c->response;  /**< a short alias */
+  struct MHD_Response *const r = c->rp.response;  /**< a short alias */
 
   mhd_assert (NULL != r);
   if (MHD_CONN_MUST_CLOSE == c->keepalive)
@@ -1312,7 +1314,7 @@ keepalive_possible (struct MHD_Connection *connection)
     /* No "close" token is enforced by 'add_response_header_connection()' */
     mhd_assert (0 == (r->flags_auto & MHD_RAF_HAS_CONNECTION_CLOSE));
     /* Valid HTTP version is enforced by 'MHD_queue_response()' */
-    mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (c->http_ver));
+    mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (c->rq.http_ver));
     mhd_assert (! c->stop_with_error);
     return MHD_CONN_MUST_UPGRADE;
   }
@@ -1327,7 +1329,7 @@ keepalive_possible (struct MHD_Connection *connection)
   if (0 != (r->flags_auto & MHD_RAF_HAS_CONNECTION_CLOSE))
     return MHD_CONN_MUST_CLOSE;
 
-  if (! MHD_IS_HTTP_VER_SUPPORTED (c->http_ver))
+  if (! MHD_IS_HTTP_VER_SUPPORTED (c->rq.http_ver))
     return MHD_CONN_MUST_CLOSE;
 
   if (MHD_lookup_header_s_token_ci (c,
@@ -1335,8 +1337,8 @@ keepalive_possible (struct MHD_Connection *connection)
                                     "close"))
     return MHD_CONN_MUST_CLOSE;
 
-  if ((MHD_HTTP_VER_1_0 == connection->http_ver) ||
-      (0 != (connection->response->flags & MHD_RF_HTTP_1_0_SERVER)))
+  if ((MHD_HTTP_VER_1_0 == connection->rq.http_ver) ||
+      (0 != (connection->rp.response->flags & MHD_RF_HTTP_1_0_SERVER)))
   {
     if (MHD_lookup_header_s_token_ci (connection,
                                       MHD_HTTP_HEADER_CONNECTION,
@@ -1346,7 +1348,7 @@ keepalive_possible (struct MHD_Connection *connection)
     return MHD_CONN_MUST_CLOSE;
   }
 
-  if (MHD_IS_HTTP_VER_1_1_COMPAT (c->http_ver))
+  if (MHD_IS_HTTP_VER_1_1_COMPAT (c->rq.http_ver))
     return MHD_CONN_USE_KEEPALIVE;
 
   return MHD_CONN_MUST_CLOSE;
@@ -1728,7 +1730,7 @@ is_reply_body_needed (struct MHD_Connection *connection,
 #if 0
   /* This check is not needed as upgrade handler is used only with code 101 */
 #ifdef UPGRADE_SUPPORT
-  if (NULL != response->upgrade_handler)
+  if (NULL != rp.response->upgrade_handler)
     return RP_BODY_NONE;
 #endif /* UPGRADE_SUPPORT */
 #endif
@@ -1737,7 +1739,7 @@ is_reply_body_needed (struct MHD_Connection *connection,
   /* CONNECT is not supported by MHD */
   /* Successful responses for connect requests are filtered by
    * MHD_queue_response() */
-  if ( (MHD_HTTP_MTHD_CONNECT == c->http_mthd) &&
+  if ( (MHD_HTTP_MTHD_CONNECT == c->rq.http_mthd) &&
        (2 == rcode / 100) )
     return false; /* Actually pass-through CONNECT is not supported by MHD */
 #endif
@@ -1745,7 +1747,7 @@ is_reply_body_needed (struct MHD_Connection *connection,
   /* Reply body headers could be used.
    * Check whether reply body itself must be used. */
 
-  if (MHD_HTTP_MTHD_HEAD == c->http_mthd)
+  if (MHD_HTTP_MTHD_HEAD == c->rq.http_mthd)
     return RP_BODY_HEADERS_ONLY;
 
   if (MHD_HTTP_NOT_MODIFIED == rcode)
@@ -1770,7 +1772,7 @@ static void
 setup_reply_properties (struct MHD_Connection *connection)
 {
   struct MHD_Connection *const c = connection; /**< a short alias */
-  struct MHD_Response *const r = c->response;  /**< a short alias */
+  struct MHD_Response *const r = c->rp.response;  /**< a short alias */
   enum replyBodyUse use_rp_body;
   bool use_chunked;
 
@@ -1779,22 +1781,22 @@ setup_reply_properties (struct MHD_Connection 
*connection)
   /* ** Adjust reply properties ** */
 
   c->keepalive = keepalive_possible (c);
-  use_rp_body = is_reply_body_needed (c, c->responseCode);
-  c->rp_props.send_reply_body = (use_rp_body > RP_BODY_HEADERS_ONLY);
-  c->rp_props.use_reply_body_headers = (use_rp_body >= RP_BODY_HEADERS_ONLY);
+  use_rp_body = is_reply_body_needed (c, c->rp.responseCode);
+  c->rp.props.send_reply_body = (use_rp_body > RP_BODY_HEADERS_ONLY);
+  c->rp.props.use_reply_body_headers = (use_rp_body >= RP_BODY_HEADERS_ONLY);
 
 #ifdef UPGRADE_SUPPORT
   mhd_assert ((NULL == r->upgrade_handler) || (RP_BODY_NONE == use_rp_body));
 #endif /* UPGRADE_SUPPORT */
 
-  if (c->rp_props.use_reply_body_headers)
+  if (c->rp.props.use_reply_body_headers)
   {
     if ((MHD_SIZE_UNKNOWN == r->total_size) ||
         (0 != (r->flags_auto & MHD_RAF_HAS_TRANS_ENC_CHUNKED)))
     { /* Use chunked reply encoding if possible */
 
       /* Check whether chunked encoding is supported by the client */
-      if (! MHD_IS_HTTP_VER_1_1_COMPAT (c->http_ver))
+      if (! MHD_IS_HTTP_VER_1_1_COMPAT (c->rq.http_ver))
         use_chunked = false;
       /* Check whether chunked encoding is allowed for the reply */
       else if (0 != (r->flags & (MHD_RF_HTTP_1_0_COMPATIBLE_STRICT
@@ -1820,8 +1822,8 @@ setup_reply_properties (struct MHD_Connection *connection)
   else
     use_chunked = false; /* chunked encoding cannot be used without body */
 
-  c->rp_props.chunked = use_chunked;
-  c->rp_props.set = true;
+  c->rp.props.chunked = use_chunked;
+  c->rp.props.set = true;
 }
 
 
@@ -1833,25 +1835,25 @@ static void
 check_connection_reply (struct MHD_Connection *connection)
 {
   struct MHD_Connection *const c = connection; /**< a short alias */
-  struct MHD_Response *const r = c->response;  /**< a short alias */
-  mhd_assert (c->rp_props.set);
+  struct MHD_Response *const r = c->rp.response;  /**< a short alias */
+  mhd_assert (c->rp.props.set);
 
 #ifdef HAVE_MESSAGES
-  if ((! c->rp_props.use_reply_body_headers) && (0 != r->total_size))
+  if ((! c->rp.props.use_reply_body_headers) && (0 != r->total_size))
   {
     MHD_DLOG (c->daemon,
               _ ("This reply with response code %u cannot use reply body. "
                  "Non-empty response body is ignored and not used.\n"),
-              (unsigned) (c->responseCode));
+              (unsigned) (c->rp.responseCode));
   }
-  if ( (! c->rp_props.use_reply_body_headers) &&
+  if ( (! c->rp.props.use_reply_body_headers) &&
        (0 != (r->flags_auto & MHD_RAF_HAS_CONTENT_LENGTH)) )
   {
     MHD_DLOG (c->daemon,
               _ ("This reply with response code %u cannot use reply body. "
                  "Application defined \"Content-Length\" header violates"
                  "HTTP specification.\n"),
-              (unsigned) (c->responseCode));
+              (unsigned) (c->rp.responseCode));
   }
 #else
   (void) c; /* Mute compiler warning */
@@ -2037,14 +2039,14 @@ static enum MHD_Result
 build_header_response (struct MHD_Connection *connection)
 {
   struct MHD_Connection *const c = connection; /**< a short alias */
-  struct MHD_Response *const r = c->response;  /**< a short alias */
-  char *buf;                                   /**< the output buffer */
-  size_t pos;                                  /**< append offset in the @a 
buf */
-  size_t buf_size;                             /**< the size of the @a buf */
-  size_t el_size;                              /**< the size of current 
element to be added to the @a buf */
-  unsigned rcode;                              /**< the response code */
-  bool use_conn_close;                         /**< Use "Connection: close" 
header */
-  bool use_conn_k_alive;                       /**< Use "Connection: 
Keep-Alive" header */
+  struct MHD_Response *const r = c->rp.response; /**< a short alias */
+  char *buf;                                     /**< the output buffer */
+  size_t pos;                                    /**< append offset in the @a 
buf */
+  size_t buf_size;                               /**< the size of the @a buf */
+  size_t el_size;                                /**< the size of current 
element to be added to the @a buf */
+  unsigned rcode;                                /**< the response code */
+  bool use_conn_close;                           /**< Use "Connection: close" 
header */
+  bool use_conn_k_alive;                         /**< Use "Connection: 
Keep-Alive" header */
 
   mhd_assert (NULL != r);
 
@@ -2052,7 +2054,7 @@ build_header_response (struct MHD_Connection *connection)
 
   setup_reply_properties (c);
 
-  mhd_assert (c->rp_props.set);
+  mhd_assert (c->rp.props.set);
   mhd_assert ((MHD_CONN_MUST_CLOSE == c->keepalive) || \
               (MHD_CONN_USE_KEEPALIVE == c->keepalive) || \
               (MHD_CONN_MUST_UPGRADE == c->keepalive));
@@ -2062,17 +2064,17 @@ build_header_response (struct MHD_Connection 
*connection)
 #else  /* ! UPGRADE_SUPPORT */
   mhd_assert (MHD_CONN_MUST_UPGRADE != c->keepalive);
 #endif /* ! UPGRADE_SUPPORT */
-  mhd_assert ((! c->rp_props.chunked) || c->rp_props.use_reply_body_headers);
-  mhd_assert ((! c->rp_props.send_reply_body) || \
-              c->rp_props.use_reply_body_headers);
+  mhd_assert ((! c->rp.props.chunked) || c->rp.props.use_reply_body_headers);
+  mhd_assert ((! c->rp.props.send_reply_body) || \
+              c->rp.props.use_reply_body_headers);
 #ifdef UPGRADE_SUPPORT
   mhd_assert (NULL == r->upgrade_handler || \
-              ! c->rp_props.use_reply_body_headers);
+              ! c->rp.props.use_reply_body_headers);
 #endif /* UPGRADE_SUPPORT */
 
   check_connection_reply (c);
 
-  rcode = (unsigned) c->responseCode;
+  rcode = (unsigned) c->rp.responseCode;
   if (MHD_CONN_MUST_CLOSE == c->keepalive)
   {
     /* The closure of connection must be always indicated by header
@@ -2088,7 +2090,7 @@ build_header_response (struct MHD_Connection *connection)
      * For HTTP/1.1 add header only if explicitly requested by app
      * (by response flag), as "Keep-Alive" is default for HTTP/1.1. */
     if ((0 != (r->flags & MHD_RF_SEND_KEEP_ALIVE_HEADER)) ||
-        (MHD_HTTP_VER_1_0 == c->http_ver) ||
+        (MHD_HTTP_VER_1_0 == c->rq.http_ver) ||
         (0 != (r->flags & MHD_RF_HTTP_1_0_SERVER)))
       use_conn_k_alive = true;
     else
@@ -2114,7 +2116,7 @@ build_header_response (struct MHD_Connection *connection)
   /* * The status line * */
 
   /* The HTTP version */
-  if (! c->responseIcy)
+  if (! c->rp.responseIcy)
   { /* HTTP reply */
     if (0 == (r->flags & MHD_RF_HTTP_1_0_SERVER))
     { /* HTTP/1.1 reply */
@@ -2197,8 +2199,8 @@ build_header_response (struct MHD_Connection *connection)
   /* User-defined headers */
 
   if (! add_user_headers (buf, &pos, buf_size, r,
-                          ! c->rp_props.chunked,
-                          (! c->rp_props.use_reply_body_headers) &&
+                          ! c->rp.props.chunked,
+                          (! c->rp.props.use_reply_body_headers) &&
                           (0 ==
                            (r->flags & MHD_RF_INSANITY_HEADER_CONTENT_LENGTH)),
                           use_conn_close,
@@ -2207,12 +2209,12 @@ build_header_response (struct MHD_Connection 
*connection)
 
   /* Other automatic headers */
 
-  if ( (c->rp_props.use_reply_body_headers) &&
+  if ( (c->rp.props.use_reply_body_headers) &&
        (0 == (r->flags & MHD_RF_HEAD_ONLY_RESPONSE)) )
   {
     /* Body-specific headers */
 
-    if (c->rp_props.chunked)
+    if (c->rp.props.chunked)
     { /* Chunked encoding is used */
       if (0 == (r->flags_auto & MHD_RAF_HAS_TRANS_ENC_CHUNKED))
       { /* No chunked encoding header set by user */
@@ -2275,11 +2277,11 @@ build_connection_chunked_response_footer (struct 
MHD_Connection *connection)
   struct MHD_Connection *const c = connection; /**< a short alias */
   struct MHD_HTTP_Res_Header *pos;
 
-  mhd_assert (connection->rp_props.chunked);
+  mhd_assert (connection->rp.props.chunked);
   /* TODO: allow combining of the final footer with the last chunk,
    * modify the next assert. */
   mhd_assert (MHD_CONNECTION_BODY_SENT == connection->state);
-  mhd_assert (NULL != c->response);
+  mhd_assert (NULL != c->rp.response);
 
   buf_size = connection_maximize_write_buffer (c);
   /* '5' is the minimal size of chunked footer ("0\r\n\r\n") */
@@ -2293,7 +2295,7 @@ build_connection_chunked_response_footer (struct 
MHD_Connection *connection)
   buf[used_size++] = '\r';
   buf[used_size++] = '\n';
 
-  for (pos = c->response->first_header; NULL != pos; pos = pos->next)
+  for (pos = c->rp.response->first_header; NULL != pos; pos = pos->next)
   {
     if (MHD_FOOTER_KIND == pos->kind)
     {
@@ -2387,10 +2389,10 @@ transmit_error_response_len (struct MHD_Connection 
*connection,
     connection->read_buffer_size = 0;
     connection->read_buffer_offset = 0;
   }
-  if (NULL != connection->response)
+  if (NULL != connection->rp.response)
   {
-    MHD_destroy_response (connection->response);
-    connection->response = NULL;
+    MHD_destroy_response (connection->rp.response);
+    connection->rp.response = NULL;
   }
   response = MHD_create_response_from_buffer_static (message_len,
                                                      message);
@@ -2418,20 +2420,20 @@ transmit_error_response_len (struct MHD_Connection 
*connection,
                                "(failed to queue error response)."));
     return;
   }
-  mhd_assert (NULL != connection->response);
+  mhd_assert (NULL != connection->rp.response);
   /* Do not reuse this connection. */
   connection->keepalive = MHD_CONN_MUST_CLOSE;
   if (MHD_NO == build_header_response (connection))
   {
     /* No memory. Release everything. */
-    connection->version = NULL;
-    connection->method = NULL;
-    connection->url = NULL;
-    connection->url_len = 0;
-    connection->last = NULL;
-    connection->colon = NULL;
-    connection->headers_received = NULL;
-    connection->headers_received_tail = NULL;
+    connection->rq.version = NULL;
+    connection->rq.method = NULL;
+    connection->rq.url = NULL;
+    connection->rq.url_len = 0;
+    connection->rq.last = NULL;
+    connection->rq.colon = NULL;
+    connection->rq.headers_received = NULL;
+    connection->rq.headers_received_tail = NULL;
     connection->write_buffer = NULL;
     connection->write_buffer_size = 0;
     connection->write_buffer_send_offset = 0;
@@ -2525,7 +2527,7 @@ MHD_connection_update_event_loop_info (struct 
MHD_Connection *connection)
       if ( (connection->read_buffer_offset == connection->read_buffer_size) &&
            (! try_grow_read_buffer (connection, true)) )
       {
-        if (connection->url != NULL)
+        if (connection->rq.url != NULL)
           transmit_error_response_static (connection,
                                           
MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE,
                                           REQUEST_TOO_BIG);
@@ -2707,7 +2709,7 @@ get_next_header_line (struct MHD_Connection *connection,
   if ( (connection->read_buffer_offset == connection->read_buffer_size) &&
        (! try_grow_read_buffer (connection, true)) )
   {
-    if (NULL != connection->url)
+    if (NULL != connection->rq.url)
       transmit_error_response_static (connection,
                                       MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE,
                                       REQUEST_TOO_BIG);
@@ -3160,7 +3162,7 @@ parse_http_version (struct MHD_Connection *connection,
       ((h[5] < '0') || (h[5] > '9')) ||
       ((h[7] < '0') || (h[7] > '9')))
   {
-    connection->http_ver = MHD_HTTP_VER_INVALID;
+    connection->rq.http_ver = MHD_HTTP_VER_INVALID;
     transmit_error_response_static (connection,
                                     MHD_HTTP_BAD_REQUEST,
                                     REQUEST_MALFORMED);
@@ -3170,11 +3172,11 @@ parse_http_version (struct MHD_Connection *connection,
   {
     /* HTTP/1.x */
     if (1 == h[7] - '0')
-      connection->http_ver = MHD_HTTP_VER_1_1;
+      connection->rq.http_ver = MHD_HTTP_VER_1_1;
     else if (0 == h[7] - '0')
-      connection->http_ver = MHD_HTTP_VER_1_0;
+      connection->rq.http_ver = MHD_HTTP_VER_1_0;
     else
-      connection->http_ver = MHD_HTTP_VER_1_2__1_9;
+      connection->rq.http_ver = MHD_HTTP_VER_1_2__1_9;
 
     return MHD_YES;
   }
@@ -3182,14 +3184,14 @@ parse_http_version (struct MHD_Connection *connection,
   if (0 == h[5] - '0')
   {
     /* Too old major version */
-    connection->http_ver = MHD_HTTP_VER_TOO_OLD;
+    connection->rq.http_ver = MHD_HTTP_VER_TOO_OLD;
     transmit_error_response_static (connection,
                                     MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED,
                                     REQ_HTTP_VER_IS_TOO_OLD);
     return MHD_NO;
   }
 
-  connection->http_ver = MHD_HTTP_VER_FUTURE;
+  connection->rq.http_ver = MHD_HTTP_VER_FUTURE;
   transmit_error_response_static (connection,
                                   MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED,
                                   REQ_HTTP_VER_IS_NOT_SUPPORTED);
@@ -3219,30 +3221,30 @@ parse_http_std_method (struct MHD_Connection 
*connection,
 
   if ((MHD_STATICSTR_LEN_ (MHD_HTTP_METHOD_GET) == len) &&
       (0 == memcmp (m, MHD_HTTP_METHOD_GET, len)))
-    connection->http_mthd = MHD_HTTP_MTHD_GET;
+    connection->rq.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;
+    connection->rq.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;
+    connection->rq.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;
+    connection->rq.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;
+    connection->rq.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;
+    connection->rq.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;
+    connection->rq.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;
+    connection->rq.http_mthd = MHD_HTTP_MTHD_TRACE;
   else
-    connection->http_mthd = MHD_HTTP_MTHD_OTHER;
+    connection->rq.http_mthd = MHD_HTTP_MTHD_OTHER;
 
   /* Any method string with non-zero length is valid */
   return MHD_YES;
@@ -3273,8 +3275,8 @@ parse_initial_message_line (struct MHD_Connection 
*connection,
                              line_len)))
     return MHD_NO;              /* serious error */
   uri[0] = '\0';
-  connection->method = line;
-  if (MHD_NO == parse_http_std_method (connection, connection->method,
+  connection->rq.method = line;
+  if (MHD_NO == parse_http_std_method (connection, connection->rq.method,
                                        (size_t) (uri - line)))
     return MHD_NO;
   uri++;
@@ -3289,9 +3291,9 @@ parse_initial_message_line (struct MHD_Connection 
*connection,
     /* No URI and no http version given */
     curi = "";
     uri = NULL;
-    connection->version = "";
+    connection->rq.version = "";
     args = NULL;
-    if (MHD_NO == parse_http_version (connection, connection->version, 0))
+    if (MHD_NO == parse_http_version (connection, connection->rq.version, 0))
       return MHD_NO;
   }
   else
@@ -3313,18 +3315,18 @@ parse_initial_message_line (struct MHD_Connection 
*connection,
     {
       /* http_version points to character before HTTP version string */
       http_version[0] = '\0';
-      connection->version = http_version + 1;
-      if (MHD_NO == parse_http_version (connection, connection->version,
+      connection->rq.version = http_version + 1;
+      if (MHD_NO == parse_http_version (connection, connection->rq.version,
                                         line_len
                                         - (size_t)
-                                        (connection->version - line)))
+                                        (connection->rq.version - line)))
         return MHD_NO;
       uri_len = (size_t) (http_version - uri);
     }
     else
     {
-      connection->version = "";
-      if (MHD_NO == parse_http_version (connection, connection->version, 0))
+      connection->rq.version = "";
+      if (MHD_NO == parse_http_version (connection, connection->rq.version, 0))
         return MHD_NO;
       uri_len = line_len - (size_t) (uri - line);
     }
@@ -3346,8 +3348,8 @@ parse_initial_message_line (struct MHD_Connection 
*connection,
   /* log callback before we modify URI *or* args */
   if (NULL != daemon->uri_log_callback)
   {
-    connection->client_aware = true;
-    connection->client_context
+    connection->rq.client_aware = true;
+    connection->rq.client_context
       = daemon->uri_log_callback (daemon->uri_log_callback_cls,
                                   uri,
                                   connection);
@@ -3368,15 +3370,15 @@ parse_initial_message_line (struct MHD_Connection 
*connection,
   /* unescape URI *after* searching for arguments and log callback */
   if (NULL != uri)
   {
-    connection->url_len =
+    connection->rq.url_len =
       daemon->unescape_callback (daemon->unescape_callback_cls,
                                  connection,
                                  uri);
   }
   else
-    connection->url_len = 0;
+    connection->rq.url_len = 0;
 
-  connection->url = curi;
+  connection->rq.url = curi;
   return MHD_YES;
 }
 
@@ -3394,19 +3396,19 @@ call_connection_handler (struct MHD_Connection 
*connection)
   struct MHD_Daemon *daemon = connection->daemon;
   size_t processed;
 
-  if (NULL != connection->response)
+  if (NULL != connection->rp.response)
     return;                     /* already queued a response */
   processed = 0;
-  connection->client_aware = true;
+  connection->rq.client_aware = true;
   if (MHD_NO ==
       daemon->default_handler (daemon->default_handler_cls,
                                connection,
-                               connection->url,
-                               connection->method,
-                               connection->version,
+                               connection->rq.url,
+                               connection->rq.method,
+                               connection->rq.version,
                                NULL,
                                &processed,
-                               &connection->client_context))
+                               &connection->rq.client_context))
   {
     /* serious internal error, close connection */
     CONNECTION_CLOSE_ERROR (connection,
@@ -3432,7 +3434,7 @@ process_request_body (struct MHD_Connection *connection)
   bool instant_retry;
   char *buffer_head;
 
-  if (NULL != connection->response)
+  if (NULL != connection->rp.response)
   {
     /* TODO: discard all read buffer as early response
      * means that connection have to be closed. */
@@ -3440,9 +3442,9 @@ process_request_body (struct MHD_Connection *connection)
        (but not more, there might be another request after it) */
     size_t purge;
 
-    purge = (size_t) MHD_MIN (connection->remaining_upload_size,
+    purge = (size_t) MHD_MIN (connection->rq.remaining_upload_size,
                               (uint64_t) connection->read_buffer_offset);
-    connection->remaining_upload_size -= purge;
+    connection->rq.remaining_upload_size -= purge;
     if (connection->read_buffer_offset > purge)
       memmove (connection->read_buffer,
                &connection->read_buffer[purge],
@@ -3460,12 +3462,12 @@ process_request_body (struct MHD_Connection *connection)
     size_t processed_size;
 
     instant_retry = false;
-    if (connection->have_chunked_upload)
+    if (connection->rq.have_chunked_upload)
     {
-      mhd_assert (MHD_SIZE_UNKNOWN == connection->remaining_upload_size);
-      if ( (connection->current_chunk_offset ==
-            connection->current_chunk_size) &&
-           (0 != connection->current_chunk_size) )
+      mhd_assert (MHD_SIZE_UNKNOWN == connection->rq.remaining_upload_size);
+      if ( (connection->rq.current_chunk_offset ==
+            connection->rq.current_chunk_size) &&
+           (0 != connection->rq.current_chunk_size) )
       {
         size_t i;
         mhd_assert (0 != available);
@@ -3489,21 +3491,22 @@ process_request_body (struct MHD_Connection *connection)
         }
         available -= i;
         buffer_head += i;
-        connection->current_chunk_offset = 0;
-        connection->current_chunk_size = 0;
+        connection->rq.current_chunk_offset = 0;
+        connection->rq.current_chunk_size = 0;
         if (0 == available)
           break;
       }
-      if (0 != connection->current_chunk_size)
+      if (0 != connection->rq.current_chunk_size)
       {
         uint64_t cur_chunk_left;
-        mhd_assert (connection->current_chunk_offset < \
-                    connection->current_chunk_size);
+        mhd_assert (connection->rq.current_chunk_offset < \
+                    connection->rq.current_chunk_size);
         /* we are in the middle of a chunk, give
            as much as possible to the client (without
            crossing chunk boundaries) */
         cur_chunk_left
-          = connection->current_chunk_size - connection->current_chunk_offset;
+          = connection->rq.current_chunk_size
+            - connection->rq.current_chunk_offset;
         if (cur_chunk_left > available)
           to_be_processed = available;
         else
@@ -3583,15 +3586,15 @@ process_request_body (struct MHD_Connection *connection)
 
             mhd_assert (found_chunk_size_str);
             /* Start reading payload data of the chunk */
-            connection->current_chunk_offset = 0;
-            connection->current_chunk_size = chunk_size;
+            connection->rq.current_chunk_offset = 0;
+            connection->rq.current_chunk_size = chunk_size;
             i++; /* Consume the last checked char */
             available -= i;
             buffer_head += i;
 
-            if (0 == connection->current_chunk_size)
+            if (0 == connection->rq.current_chunk_size)
             { /* The final (termination) chunk */
-              connection->remaining_upload_size = 0;
+              connection->rq.remaining_upload_size = 0;
               break;
             }
             if (available > 0)
@@ -3629,24 +3632,24 @@ process_request_body (struct MHD_Connection *connection)
     else
     {
       /* no chunked encoding, give all to the client */
-      mhd_assert (MHD_SIZE_UNKNOWN != connection->remaining_upload_size);
-      mhd_assert (0 != connection->remaining_upload_size);
-      if (connection->remaining_upload_size < available)
-        to_be_processed = (size_t) connection->remaining_upload_size;
+      mhd_assert (MHD_SIZE_UNKNOWN != connection->rq.remaining_upload_size);
+      mhd_assert (0 != connection->rq.remaining_upload_size);
+      if (connection->rq.remaining_upload_size < available)
+        to_be_processed = (size_t) connection->rq.remaining_upload_size;
       else
         to_be_processed = available;
     }
     left_unprocessed = to_be_processed;
-    connection->client_aware = true;
+    connection->rq.client_aware = true;
     if (MHD_NO ==
         daemon->default_handler (daemon->default_handler_cls,
                                  connection,
-                                 connection->url,
-                                 connection->method,
-                                 connection->version,
+                                 connection->rq.url,
+                                 connection->rq.method,
+                                 connection->rq.version,
                                  buffer_head,
                                  &left_unprocessed,
-                                 &connection->client_context))
+                                 &connection->rq.client_context))
     {
       /* serious internal error, close connection */
       CONNECTION_CLOSE_ERROR (connection,
@@ -3671,18 +3674,18 @@ process_request_body (struct MHD_Connection *connection)
 #endif
     }
     processed_size = to_be_processed - left_unprocessed;
-    if (connection->have_chunked_upload)
-      connection->current_chunk_offset += processed_size;
+    if (connection->rq.have_chunked_upload)
+      connection->rq.current_chunk_offset += processed_size;
     /* dh left "processed" bytes in buffer for next time... */
     buffer_head += processed_size;
     available -= processed_size;
-    if (! connection->have_chunked_upload)
+    if (! connection->rq.have_chunked_upload)
     {
-      mhd_assert (MHD_SIZE_UNKNOWN != connection->remaining_upload_size);
-      connection->remaining_upload_size -= processed_size;
+      mhd_assert (MHD_SIZE_UNKNOWN != connection->rq.remaining_upload_size);
+      connection->rq.remaining_upload_size -= processed_size;
     }
     else
-      mhd_assert (MHD_SIZE_UNKNOWN == connection->remaining_upload_size);
+      mhd_assert (MHD_SIZE_UNKNOWN == connection->rq.remaining_upload_size);
   } while (instant_retry);
   /* TODO: zero out reused memory region */
   if ( (available > 0) &&
@@ -3771,8 +3774,8 @@ process_header_line (struct MHD_Connection *connection,
      loop since we need to be able to inspect
      the *next* header line (in case it starts
      with a space...) */
-  connection->last = line;
-  connection->colon = colon;
+  connection->rq.last = line;
+  connection->rq.colon = colon;
   return MHD_YES;
 }
 
@@ -3797,7 +3800,7 @@ process_broken_line (struct MHD_Connection *connection,
   size_t last_len;
   size_t tmp_len;
 
-  last = connection->last;
+  last = connection->rq.last;
   if ( (' ' == line[0]) ||
        ('\t' == line[0]) )
   {
@@ -3833,17 +3836,17 @@ process_broken_line (struct MHD_Connection *connection,
     memcpy (&last[last_len],
             tmp,
             tmp_len + 1);
-    connection->last = last;
+    connection->rq.last = last;
     return MHD_YES;             /* possibly more than 2 lines... */
   }
   mhd_assert ( (NULL != last) &&
-               (NULL != connection->colon) );
+               (NULL != connection->rq.colon) );
   if (MHD_NO ==
       connection_add_header (connection,
                              last,
                              strlen (last),
-                             connection->colon,
-                             strlen (connection->colon),
+                             connection->rq.colon,
+                             strlen (connection->rq.colon),
                              kind))
   {
     /* Error has been queued by connection_add_header() */
@@ -3913,7 +3916,7 @@ parse_connection_headers (struct MHD_Connection 
*connection)
   }
 #endif /* COOKIE_SUPPORT */
   if ( (1 <= connection->daemon->strict_for_client) &&
-       (MHD_IS_HTTP_VER_1_1_COMPAT (connection->http_ver)) &&
+       (MHD_IS_HTTP_VER_1_1_COMPAT (connection->rq.http_ver)) &&
        (MHD_NO ==
         MHD_lookup_connection_value_n (connection,
                                        MHD_HEADER_KIND,
@@ -3933,7 +3936,7 @@ parse_connection_headers (struct MHD_Connection 
*connection)
     return;
   }
 
-  connection->remaining_upload_size = 0;
+  connection->rq.remaining_upload_size = 0;
   if (MHD_NO != MHD_lookup_connection_value_n (connection,
                                                MHD_HEADER_KIND,
                                                
MHD_HTTP_HEADER_TRANSFER_ENCODING,
@@ -3942,10 +3945,10 @@ parse_connection_headers (struct MHD_Connection 
*connection)
                                                &enc,
                                                NULL))
   {
-    connection->remaining_upload_size = MHD_SIZE_UNKNOWN;
+    connection->rq.remaining_upload_size = MHD_SIZE_UNKNOWN;
     if (MHD_str_equal_caseless_ (enc,
                                  "chunked"))
-      connection->have_chunked_upload = true;
+      connection->rq.have_chunked_upload = true;
   }
   else
   {
@@ -3961,11 +3964,11 @@ parse_connection_headers (struct MHD_Connection 
*connection)
 
       num_digits = MHD_str_to_uint64_n_ (clen,
                                          val_len,
-                                         &connection->remaining_upload_size);
+                                         
&connection->rq.remaining_upload_size);
       if ( (val_len != num_digits) ||
            (0 == num_digits) )
       {
-        connection->remaining_upload_size = 0;
+        connection->rq.remaining_upload_size = 0;
         if ((0 == num_digits) &&
             (0 != val_len) &&
             ('0' <= clen[0]) && ('9' >= clen[0]))
@@ -4273,7 +4276,7 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
 #ifdef HAVE_MESSAGES
       MHD_DLOG (connection->daemon,
                 _ ("Failed to send data in request for %s.\n"),
-                connection->url);
+                connection->rq.url);
 #endif
       CONNECTION_CLOSE_ERROR (connection,
                               NULL);
@@ -4298,7 +4301,7 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
     return;
   case MHD_CONNECTION_HEADERS_SENDING:
     {
-      struct MHD_Response *const resp = connection->response;
+      struct MHD_Response *const resp = connection->rp.response;
       const size_t wb_ready = connection->write_buffer_append_offset
                               - connection->write_buffer_send_offset;
       mhd_assert (connection->write_buffer_append_offset >= \
@@ -4307,18 +4310,18 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
       mhd_assert ( (0 == resp->data_size) || \
                    (0 == resp->data_start) || \
                    (NULL != resp->crc) );
-      mhd_assert ( (0 == connection->response_write_position) || \
+      mhd_assert ( (0 == connection->rp.rsp_write_position) || \
                    (resp->total_size ==
-                    connection->response_write_position) );
+                    connection->rp.rsp_write_position) );
       mhd_assert ((MHD_CONN_MUST_UPGRADE != connection->keepalive) || \
-                  (! connection->rp_props.send_reply_body));
+                  (! connection->rp.props.send_reply_body));
 
-      if ( (connection->rp_props.send_reply_body) &&
+      if ( (connection->rp.props.send_reply_body) &&
            (NULL == resp->crc) &&
            (NULL == resp->data_iov) &&
            /* TODO: remove the next check as 'send_reply_body' is used */
-           (0 == connection->response_write_position) &&
-           (! connection->rp_props.chunked) )
+           (0 == connection->rp.rsp_write_position) &&
+           (! connection->rp.props.chunked) )
       {
         mhd_assert (resp->total_size >= resp->data_size);
         mhd_assert (0 == resp->data_start);
@@ -4346,7 +4349,7 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
                                       NULL,
                                       0,
                                       ((0 == resp->total_size) ||
-                                       (! connection->rp_props.send_reply_body)
+                                       (! connection->rp.props.send_reply_body)
                                       ));
       }
 
@@ -4358,7 +4361,7 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
         MHD_DLOG (connection->daemon,
                   _ ("Failed to send the response headers for the " \
                      "request for `%s'. Error: %s\n"),
-                  connection->url,
+                  connection->rq.url,
                   str_conn_error_ (ret));
 #endif
         CONNECTION_CLOSE_ERROR (connection,
@@ -4370,11 +4373,11 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
       {
         /* The complete header and some response data have been sent,
          * update both offsets. */
-        mhd_assert (0 == connection->response_write_position);
-        mhd_assert (! connection->rp_props.chunked);
-        mhd_assert (connection->rp_props.send_reply_body);
+        mhd_assert (0 == connection->rp.rsp_write_position);
+        mhd_assert (! connection->rp.props.chunked);
+        mhd_assert (connection->rp.props.send_reply_body);
         connection->write_buffer_send_offset += wb_ready;
-        connection->response_write_position = ((size_t) ret) - wb_ready;
+        connection->rp.rsp_write_position = ((size_t) ret) - wb_ready;
       }
       else
         connection->write_buffer_send_offset += (size_t) ret;
@@ -4388,9 +4391,9 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
   case MHD_CONNECTION_HEADERS_SENT:
     return;
   case MHD_CONNECTION_NORMAL_BODY_READY:
-    response = connection->response;
-    if (connection->response_write_position <
-        connection->response->total_size)
+    response = connection->rp.response;
+    if (connection->rp.rsp_write_position <
+        connection->rp.response->total_size)
     {
       uint64_t data_write_offset;
 
@@ -4404,7 +4407,7 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
         return;
       }
 #if defined(_MHD_HAVE_SENDFILE)
-      if (MHD_resp_sender_sendfile == connection->resp_sender)
+      if (MHD_resp_sender_sendfile == connection->rp.resp_sender)
       {
         mhd_assert (NULL == response->data_iov);
         ret = MHD_send_sendfile_ (connection);
@@ -4414,12 +4417,12 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
       if (NULL != response->data_iov)
       {
         ret = MHD_send_iovec_ (connection,
-                               &connection->resp_iov,
+                               &connection->rp.resp_iov,
                                true);
       }
       else
       {
-        data_write_offset = connection->response_write_position
+        data_write_offset = connection->rp.rsp_write_position
                             - response->data_start;
         if (data_write_offset > (uint64_t) SIZE_MAX)
           MHD_PANIC (_ ("Data offset exceeds limit.\n"));
@@ -4435,8 +4438,8 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
                    _ ("Sent %d-byte DATA response: `%.*s'\n"),
                    (int) ret,
                    (int) ret,
-                   &response->data[connection->response_write_position
-                                   - response->data_start]);
+                   &rp.response->data[connection->rp.rsp_write_position
+                                      - rp.response->data_start]);
 #endif
       }
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
@@ -4451,18 +4454,18 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
         MHD_DLOG (connection->daemon,
                   _ ("Failed to send the response body for the " \
                      "request for `%s'. Error: %s\n"),
-                  connection->url,
+                  connection->rq.url,
                   str_conn_error_ (ret));
 #endif
         CONNECTION_CLOSE_ERROR (connection,
                                 NULL);
         return;
       }
-      connection->response_write_position += (size_t) ret;
+      connection->rp.rsp_write_position += (size_t) ret;
       MHD_update_last_activity_ (connection);
     }
-    if (connection->response_write_position ==
-        connection->response->total_size)
+    if (connection->rp.rsp_write_position ==
+        connection->rp.response->total_size)
       connection->state = MHD_CONNECTION_FOOTERS_SENT;   /* have no footers */
     return;
   case MHD_CONNECTION_NORMAL_BODY_UNREADY:
@@ -4483,7 +4486,7 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
       MHD_DLOG (connection->daemon,
                 _ ("Failed to send the chunked response body for the " \
                    "request for `%s'. Error: %s\n"),
-                connection->url,
+                connection->rq.url,
                 str_conn_error_ (ret));
 #endif
       CONNECTION_CLOSE_ERROR (connection,
@@ -4495,8 +4498,8 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
     if (MHD_CONNECTION_CHUNKED_BODY_READY != connection->state)
       return;
     check_write_done (connection,
-                      (connection->response->total_size ==
-                       connection->response_write_position) ?
+                      (connection->rp.response->total_size ==
+                       connection->rp.rsp_write_position) ?
                       MHD_CONNECTION_BODY_SENT :
                       MHD_CONNECTION_CHUNKED_BODY_UNREADY);
     return;
@@ -4519,7 +4522,7 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
       MHD_DLOG (connection->daemon,
                 _ ("Failed to send the footers for the " \
                    "request for `%s'. Error: %s\n"),
-                connection->url,
+                connection->rq.url,
                 str_conn_error_ (ret));
 #endif
       CONNECTION_CLOSE_ERROR (connection,
@@ -4624,10 +4627,10 @@ cleanup_connection (struct MHD_Connection *connection)
   if (connection->in_cleanup)
     return; /* Prevent double cleanup. */
   connection->in_cleanup = true;
-  if (NULL != connection->response)
+  if (NULL != connection->rp.response)
   {
-    MHD_destroy_response (connection->response);
-    connection->response = NULL;
+    MHD_destroy_response (connection->rp.response);
+    connection->rp.response = NULL;
   }
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
   MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
@@ -4699,7 +4702,7 @@ connection_reset (struct MHD_Connection *connection,
   {
     /* Next function will destroy response, notify client,
      * destroy memory pool, and set connection state to "CLOSED" */
-    MHD_connection_close_ (connection,
+    MHD_connection_close_ (c,
                            c->stop_with_error ?
                            MHD_REQUEST_TERMINATED_WITH_ERROR :
                            MHD_REQUEST_TERMINATED_COMPLETED_OK);
@@ -4719,60 +4722,45 @@ connection_reset (struct MHD_Connection *connection,
     mhd_assert (! c->discard_request);
 
     if ( (NULL != d->notify_completed) &&
-         (c->client_aware) )
+         (c->rq.client_aware) )
       d->notify_completed (d->notify_completed_cls,
                            c,
-                           &c->client_context,
+                           &c->rq.client_context,
                            MHD_REQUEST_TERMINATED_COMPLETED_OK);
-    c->client_aware = false;
-
-    if (NULL != c->response)
-      MHD_destroy_response (c->response);
-    c->response = NULL;
-    c->version = NULL;
-    c->http_ver = MHD_HTTP_VER_UNKNOWN;
-    c->last = NULL;
-    c->colon = NULL;
-    c->header_size = 0;
-#if defined(BAUTH_SUPPORT) || defined(DAUTH_SUPPORT)
-    c->rq_auth = NULL;
-#endif
+    c->rq.client_aware = false;
+
+    if (NULL != c->rp.response)
+      MHD_destroy_response (c->rp.response);
+    c->rp.response = NULL;
+
     c->keepalive = MHD_CONN_KEEPALIVE_UNKOWN;
+    c->state = MHD_CONNECTION_INIT;
+
+    memset (&c->rq, 0, sizeof(c->rq));
+
+    /* iov (if any) will be deallocated by MHD_pool_reset */
+    memset (&c->rp, 0, sizeof(c->rp));
+
+    c->write_buffer = NULL;
+    c->write_buffer_size = 0;
+    c->write_buffer_send_offset = 0;
+    c->write_buffer_append_offset = 0;
+    c->continue_message_write_offset = 0;
+
     /* Reset the read buffer to the starting size,
        preserving the bytes we have already read. */
     new_read_buf_size = c->daemon->pool_size / 2;
     if (c->read_buffer_offset > new_read_buf_size)
       new_read_buf_size = c->read_buffer_offset;
 
-    connection->read_buffer
+    c->read_buffer
       = MHD_pool_reset (c->pool,
                         c->read_buffer,
                         c->read_buffer_offset,
                         new_read_buf_size);
     c->read_buffer_size = new_read_buf_size;
-    c->continue_message_write_offset = 0;
-    c->headers_received = NULL;
-    c->headers_received_tail = NULL;
-    c->have_chunked_upload = false;
-    c->current_chunk_size = 0;
-    c->current_chunk_offset = 0;
-    c->responseCode = 0;
-    c->responseIcy = false;
-    c->response_write_position = 0;
-    c->method = NULL;
-    c->http_mthd = MHD_HTTP_MTHD_NO_METHOD;
-    c->url = NULL;
-    c->url_len = 0;
-    memset (&c->rp_props, 0, sizeof(c->rp_props));
-    c->write_buffer = NULL;
-    c->write_buffer_size = 0;
-    c->write_buffer_send_offset = 0;
-    c->write_buffer_append_offset = 0;
-    /* iov (if any) was deallocated by MHD_pool_reset */
-    memset (&connection->resp_iov, 0, sizeof(connection->resp_iov));
-    c->state = MHD_CONNECTION_INIT;
   }
-  connection->client_context = NULL;
+  c->rq.client_context = NULL;
 }
 
 
@@ -4842,7 +4830,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
                                         NULL);
         else
         {
-          mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (connection->http_ver));
+          mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (connection->rq.http_ver));
           connection->state = MHD_CONNECTION_URL_RECEIVED;
         }
         continue;
@@ -4874,8 +4862,8 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       if (0 == line[0])
       {
         connection->state = MHD_CONNECTION_HEADERS_RECEIVED;
-        connection->header_size = (size_t) (connection->read_buffer
-                                            - connection->method);
+        connection->rq.header_size = (size_t) (connection->read_buffer
+                                               - connection->rq.method);
         continue;
       }
       if (MHD_NO == process_header_line (connection,
@@ -4911,8 +4899,8 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       if (0 == line[0])
       {
         connection->state = MHD_CONNECTION_HEADERS_RECEIVED;
-        connection->header_size = (size_t) (connection->read_buffer
-                                            - connection->method);
+        connection->rq.header_size = (size_t) (connection->read_buffer
+                                               - connection->rq.method);
         continue;
       }
       continue;
@@ -4930,21 +4918,21 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
         continue;
       if (connection->suspended)
         continue;
-      if ( (NULL == connection->response) &&
+      if ( (NULL == connection->rp.response) &&
            (need_100_continue (connection)) )
       {
         connection->state = MHD_CONNECTION_CONTINUE_SENDING;
         break;
       }
-      if ( (NULL != connection->response) &&
-           (0 != connection->remaining_upload_size) )
+      if ( (NULL != connection->rp.response) &&
+           (0 != connection->rq.remaining_upload_size) )
       {
         /* we refused (no upload allowed!) */
-        connection->remaining_upload_size = 0;
+        connection->rq.remaining_upload_size = 0;
         /* force close, in case client still tries to upload... */
         connection->discard_request = true;
       }
-      connection->state = (0 == connection->remaining_upload_size)
+      connection->state = (0 == connection->rq.remaining_upload_size)
                           ? MHD_CONNECTION_FULL_REQ_RECEIVED
                           : MHD_CONNECTION_CONTINUE_SENT;
       if (connection->suspended)
@@ -4968,12 +4956,12 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
           continue;
         }
       }
-      if ( (0 == connection->remaining_upload_size) ||
-           ( (MHD_SIZE_UNKNOWN == connection->remaining_upload_size) &&
+      if ( (0 == connection->rq.remaining_upload_size) ||
+           ( (MHD_SIZE_UNKNOWN == connection->rq.remaining_upload_size) &&
              (0 == connection->read_buffer_offset) &&
              (connection->discard_request) ) )
       {
-        if ( (connection->have_chunked_upload) &&
+        if ( (connection->rq.have_chunked_upload) &&
              (! connection->discard_request) )
           connection->state = MHD_CONNECTION_BODY_RECEIVED;
         else
@@ -5054,13 +5042,13 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       call_connection_handler (connection);     /* "final" call */
       if (connection->state == MHD_CONNECTION_CLOSED)
         continue;
-      if (NULL == connection->response)
+      if (NULL == connection->rp.response)
         break;                  /* try again next time */
       /* Response is ready, start reply */
       connection->state = MHD_CONNECTION_START_REPLY;
       continue;
     case MHD_CONNECTION_START_REPLY:
-      mhd_assert (NULL != connection->response);
+      mhd_assert (NULL != connection->rp.response);
       connection_switch_from_recv_to_send (connection);
       if (MHD_NO == build_header_response (connection))
       {
@@ -5079,12 +5067,12 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
     case MHD_CONNECTION_HEADERS_SENT:
       /* Some clients may take some actions right after header receive */
 #ifdef UPGRADE_SUPPORT
-      if (NULL != connection->response->upgrade_handler)
+      if (NULL != connection->rp.response->upgrade_handler)
       {
         connection->state = MHD_CONNECTION_UPGRADE;
         /* This connection is "upgraded".  Pass socket to application. */
         if (MHD_NO ==
-            MHD_response_execute_upgrade_ (connection->response,
+            MHD_response_execute_upgrade_ (connection->rp.response,
                                            connection))
         {
           /* upgrade failed, fail hard */
@@ -5094,16 +5082,16 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
         }
         /* Response is not required anymore for this connection. */
         {
-          struct MHD_Response *const resp = connection->response;
+          struct MHD_Response *const resp = connection->rp.response;
 
-          connection->response = NULL;
+          connection->rp.response = NULL;
           MHD_destroy_response (resp);
         }
         continue;
       }
 #endif /* UPGRADE_SUPPORT */
 
-      if (connection->rp_props.chunked)
+      if (connection->rp.props.chunked)
         connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY;
       else
         connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY;
@@ -5113,16 +5101,16 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       break;
     case MHD_CONNECTION_NORMAL_BODY_UNREADY:
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-      if (NULL != connection->response->crc)
-        MHD_mutex_lock_chk_ (&connection->response->mutex);
+      if (NULL != connection->rp.response->crc)
+        MHD_mutex_lock_chk_ (&connection->rp.response->mutex);
 #endif
-      if (0 == connection->response->total_size)
+      if (0 == connection->rp.response->total_size)
       {
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-        if (NULL != connection->response->crc)
-          MHD_mutex_unlock_chk_ (&connection->response->mutex);
+        if (NULL != connection->rp.response->crc)
+          MHD_mutex_unlock_chk_ (&connection->rp.response->mutex);
 #endif
-        if (connection->rp_props.chunked)
+        if (connection->rp.props.chunked)
           connection->state = MHD_CONNECTION_BODY_SENT;
         else
           connection->state = MHD_CONNECTION_FOOTERS_SENT;
@@ -5131,8 +5119,8 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       if (MHD_NO != try_ready_normal_body (connection))
       {
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-        if (NULL != connection->response->crc)
-          MHD_mutex_unlock_chk_ (&connection->response->mutex);
+        if (NULL != connection->rp.response->crc)
+          MHD_mutex_unlock_chk_ (&connection->rp.response->mutex);
 #endif
         connection->state = MHD_CONNECTION_NORMAL_BODY_READY;
         /* Buffering for flushable socket was already enabled*/
@@ -5147,16 +5135,16 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       break;
     case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-      if (NULL != connection->response->crc)
-        MHD_mutex_lock_chk_ (&connection->response->mutex);
+      if (NULL != connection->rp.response->crc)
+        MHD_mutex_lock_chk_ (&connection->rp.response->mutex);
 #endif
-      if ( (0 == connection->response->total_size) ||
-           (connection->response_write_position ==
-            connection->response->total_size) )
+      if ( (0 == connection->rp.response->total_size) ||
+           (connection->rp.rsp_write_position ==
+            connection->rp.response->total_size) )
       {
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-        if (NULL != connection->response->crc)
-          MHD_mutex_unlock_chk_ (&connection->response->mutex);
+        if (NULL != connection->rp.response->crc)
+          MHD_mutex_unlock_chk_ (&connection->rp.response->mutex);
 #endif
         connection->state = MHD_CONNECTION_BODY_SENT;
         continue;
@@ -5167,8 +5155,8 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
         if (MHD_NO != try_ready_chunked_body (connection, &finished))
         {
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-          if (NULL != connection->response->crc)
-            MHD_mutex_unlock_chk_ (&connection->response->mutex);
+          if (NULL != connection->rp.response->crc)
+            MHD_mutex_unlock_chk_ (&connection->rp.response->mutex);
 #endif
           connection->state = finished ? MHD_CONNECTION_BODY_SENT :
                               MHD_CONNECTION_CHUNKED_BODY_READY;
@@ -5178,7 +5166,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       }
       break;
     case MHD_CONNECTION_BODY_SENT:
-      mhd_assert (connection->rp_props.chunked);
+      mhd_assert (connection->rp.props.chunked);
 
       if (MHD_NO == build_connection_chunked_response_footer (connection))
       {
@@ -5189,7 +5177,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
         continue;
       }
       /* TODO: remove next 'if' */
-      if ( (! connection->rp_props.chunked) ||
+      if ( (! connection->rp.props.chunked) ||
            (connection->write_buffer_send_offset ==
             connection->write_buffer_append_offset) )
         connection->state = MHD_CONNECTION_FOOTERS_SENT;
@@ -5200,12 +5188,12 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       /* no default action */
       break;
     case MHD_CONNECTION_FOOTERS_SENT:
-      if (MHD_HTTP_PROCESSING == connection->responseCode)
+      if (MHD_HTTP_PROCESSING == connection->rp.responseCode)
       {
         /* After this type of response, we allow sending another! */
         connection->state = MHD_CONNECTION_HEADERS_PROCESSED;
-        MHD_destroy_response (connection->response);
-        connection->response = NULL;
+        MHD_destroy_response (connection->rp.response);
+        connection->rp.response = NULL;
         /* FIXME: maybe partially reset memory pool? */
         continue;
       }
@@ -5404,12 +5392,12 @@ MHD_get_connection_info (struct MHD_Connection 
*connection,
     if ( (MHD_CONNECTION_HEADERS_RECEIVED > connection->state) ||
          (MHD_CONNECTION_CLOSED == connection->state) )
       return NULL;   /* invalid, too early! */
-    connection->connection_info_dummy.header_size = connection->header_size;
+    connection->connection_info_dummy.header_size = connection->rq.header_size;
     return &connection->connection_info_dummy;
   case MHD_CONNECTION_INFO_HTTP_STATUS:
-    if (NULL == connection->response)
+    if (NULL == connection->rp.response)
       return NULL;
-    connection->connection_info_dummy.http_status = connection->responseCode;
+    connection->connection_info_dummy.http_status = 
connection->rp.responseCode;
     return &connection->connection_info_dummy;
   default:
     return NULL;
@@ -5562,7 +5550,7 @@ MHD_queue_response (struct MHD_Connection *connection,
     return MHD_YES; /* If daemon was shut down in parallel,
                      * response will be aborted now or on later stage. */
 
-  if ( (NULL != connection->response) ||
+  if ( (NULL != connection->rp.response) ||
        ( (MHD_CONNECTION_HEADERS_PROCESSED != connection->state) &&
          (MHD_CONNECTION_FULL_REQ_RECEIVED != connection->state) ) )
     return MHD_NO;
@@ -5613,7 +5601,7 @@ MHD_queue_response (struct MHD_Connection *connection,
 #endif
       return MHD_NO;
     }
-    if (! MHD_IS_HTTP_VER_1_1_COMPAT (connection->http_ver))
+    if (! MHD_IS_HTTP_VER_1_1_COMPAT (connection->rq.http_ver))
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
@@ -5658,7 +5646,7 @@ MHD_queue_response (struct MHD_Connection *connection,
   }
   if (200 > status_code)
   {
-    if (MHD_HTTP_VER_1_0 == connection->http_ver)
+    if (MHD_HTTP_VER_1_0 == connection->rq.http_ver)
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
@@ -5680,7 +5668,7 @@ MHD_queue_response (struct MHD_Connection *connection,
       return MHD_NO;
     }
   }
-  if ( (MHD_HTTP_MTHD_CONNECT == connection->http_mthd) &&
+  if ( (MHD_HTTP_MTHD_CONNECT == connection->rq.http_mthd) &&
        (2 == status_code / 100) )
   {
 #ifdef HAVE_MESSAGES
@@ -5716,9 +5704,9 @@ MHD_queue_response (struct MHD_Connection *connection,
 #endif
 
   MHD_increment_response_rc (response);
-  connection->response = response;
-  connection->responseCode = status_code;
-  connection->responseIcy = reply_icy;
+  connection->rp.response = response;
+  connection->rp.responseCode = status_code;
+  connection->rp.responseIcy = reply_icy;
 #if defined(_MHD_HAVE_SENDFILE)
   if ( (response->fd == -1) ||
        (response->is_pipe) ||
@@ -5729,14 +5717,14 @@ MHD_queue_response (struct MHD_Connection *connection,
 #endif /* MHD_SEND_SPIPE_SUPPRESS_NEEDED &&
           MHD_SEND_SPIPE_SUPPRESS_POSSIBLE */
        )
-    connection->resp_sender = MHD_resp_sender_std;
+    connection->rp.resp_sender = MHD_resp_sender_std;
   else
-    connection->resp_sender = MHD_resp_sender_sendfile;
+    connection->rp.resp_sender = MHD_resp_sender_sendfile;
 #endif /* _MHD_HAVE_SENDFILE */
   /* FIXME: if 'is_pipe' is set, TLS is off, and we have *splice*, we could 
use splice()
      to avoid two user-space copies... */
 
-  if ( (MHD_HTTP_MTHD_HEAD == connection->http_mthd) ||
+  if ( (MHD_HTTP_MTHD_HEAD == connection->rq.http_mthd) ||
        (MHD_HTTP_OK > status_code) ||
        (MHD_HTTP_NO_CONTENT == status_code) ||
        (MHD_HTTP_NOT_MODIFIED == status_code) )
@@ -5746,7 +5734,7 @@ MHD_queue_response (struct MHD_Connection *connection,
        have already sent the full message body. */
     /* TODO: remove the next assignment, use 'rp_props.send_reply_body' in
      * checks */
-    connection->response_write_position = response->total_size;
+    connection->rp.rsp_write_position = response->total_size;
   }
   if (MHD_CONNECTION_HEADERS_PROCESSED == connection->state)
   {
@@ -5754,7 +5742,7 @@ MHD_queue_response (struct MHD_Connection *connection,
        further requests! */
     connection->discard_request = true;
     connection->state = MHD_CONNECTION_START_REPLY;
-    connection->remaining_upload_size = 0;
+    connection->rq.remaining_upload_size = 0;
   }
   if (! connection->in_idle)
     (void) MHD_connection_handle_idle (connection);
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 7925111b..ecce17b5 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2201,12 +2201,12 @@ thread_main_handle_connection (void *data)
       /* Normal HTTP processing is finished,
        * notify application. */
       if ( (NULL != daemon->notify_completed) &&
-           (con->client_aware) )
+           (con->rq.client_aware) )
         daemon->notify_completed (daemon->notify_completed_cls,
                                   con,
-                                  &con->client_context,
+                                  &con->rq.client_context,
                                   MHD_REQUEST_TERMINATED_COMPLETED_OK);
-      con->client_aware = false;
+      con->rq.client_aware = false;
 
       thread_main_connection_upgrade (con);
       /* MHD_connection_finish_forward_() was called by 
thread_main_connection_upgrade(). */
@@ -2237,10 +2237,10 @@ thread_main_handle_connection (void *data)
                            MHD_REQUEST_TERMINATED_WITH_ERROR);
   MHD_connection_handle_idle (con);
 exit:
-  if (NULL != con->response)
+  if (NULL != con->rp.response)
   {
-    MHD_destroy_response (con->response);
-    con->response = NULL;
+    MHD_destroy_response (con->rp.response);
+    con->rp.response = NULL;
   }
 
   if (MHD_INVALID_SOCKET != con->socket_fd)
@@ -3420,13 +3420,13 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
 
       if ( (NULL != daemon->notify_completed) &&
            (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-           (pos->client_aware) )
+           (pos->rq.client_aware) )
       {
         daemon->notify_completed (daemon->notify_completed_cls,
                                   pos,
-                                  &pos->client_context,
+                                  &pos->rq.client_context,
                                   MHD_REQUEST_TERMINATED_COMPLETED_OK);
-        pos->client_aware = false;
+        pos->rq.client_aware = false;
       }
       DLL_insert (daemon->cleanup_head,
                   daemon->cleanup_tail,
@@ -3913,10 +3913,10 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
       }
     }
 #endif
-    if (NULL != pos->response)
+    if (NULL != pos->rp.response)
     {
-      MHD_destroy_response (pos->response);
-      pos->response = NULL;
+      MHD_destroy_response (pos->rp.response);
+      pos->rp.response = NULL;
     }
     if (MHD_INVALID_SOCKET != pos->socket_fd)
       MHD_socket_close_chk_ (pos->socket_fd);
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 95661a79..e9a7e35f 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -479,20 +479,6 @@ digest_calc_hash (struct DigestAlgorithm *da, uint8_t 
*digest)
 }
 
 
-static const struct MHD_RqDAuth *
-get_rq_dauth_params (struct MHD_Connection *connection)
-{
-  const struct MHD_AuthRqHeader *rq_params;
-
-  rq_params = MHD_get_auth_rq_params_ (connection);
-  if ( (NULL == rq_params) ||
-       (MHD_AUTHTYPE_DIGEST != rq_params->auth_type) )
-    return NULL;
-
-  return rq_params->params.dauth;
-}
-
-
 /**
  * Extract timestamp from the given nonce.
  * @param nonce the nonce to check
@@ -604,7 +590,7 @@ check_nonce_nc (struct MHD_Connection *connection,
   mod = daemon->nonce_nc_size;
   if (0 == mod)
     return MHD_CHECK_NONCENC_STALE;  /* no array! */
-  if (nc >= UINT64_MAX - 64)
+  if (nc >= UINT32_MAX - 64)
     return MHD_CHECK_NONCENC_STALE;  /* Overflow, unrealistically high value */
 
   nn = &daemon->nnc[get_nonce_nc_idx (mod, nonce, noncelen)];
@@ -663,7 +649,7 @@ check_nonce_nc (struct MHD_Connection *connection,
   else if (nc > nn->nc)
   {
     /* 'nc' is larger, shift bitmask and bump limit */
-    const uint64_t jump_size = nc - nn->nc;
+    const uint32_t jump_size = (uint32_t) nc - nn->nc;
     if (64 > jump_size)
     {
       /* small jump, less than mask width */
@@ -675,7 +661,7 @@ check_nonce_nc (struct MHD_Connection *connection,
       nn->nmask = (UINT64_C (1) << 63);
     else
       nn->nmask = 0;                /* big jump, unset all bits in the mask */
-    nn->nc = nc;
+    nn->nc = (uint32_t) nc;
     ret = MHD_CHECK_NONCENC_OK;
   }
   else if (nc < nn->nc)
@@ -1141,7 +1127,7 @@ MHD_digest_auth_get_request_info3 (struct MHD_Connection 
*connection)
   size_t unif_buf_used;
   enum MHD_GetRqNCResult nc_res;
 
-  params = get_rq_dauth_params (connection);
+  params = MHD_get_rq_dauth_params_ (connection);
   if (NULL == params)
     return NULL;
 
@@ -1234,7 +1220,7 @@ MHD_digest_auth_get_username3 (struct MHD_Connection 
*connection)
   uint8_t *unif_buf_ptr;
   size_t unif_buf_used;
 
-  params = get_rq_dauth_params (connection);
+  params = MHD_get_rq_dauth_params_ (connection);
   if (NULL == params)
     return NULL;
 
@@ -1288,7 +1274,7 @@ MHD_digest_auth_get_username (struct MHD_Connection 
*connection)
   size_t buf_size;
   enum MHD_DigestAuthUsernameType uname_type;
 
-  params = get_rq_dauth_params (connection);
+  params = MHD_get_rq_dauth_params_ (connection);
   if (NULL == params)
     return NULL;
 
@@ -1505,12 +1491,12 @@ calculate_add_nonce (struct MHD_Connection *const 
connection,
   mhd_assert (0 != nonce_size);
 
   calculate_nonce (timestamp,
-                   connection->method,
+                   connection->rq.method,
                    daemon->digest_auth_random,
                    daemon->digest_auth_rand_size,
-                   connection->url,
-                   connection->url_len,
-                   connection->headers_received,
+                   connection->rq.url,
+                   connection->rq.url_len,
+                   connection->rq.headers_received,
                    realm,
                    realm_len,
                    da,
@@ -1654,7 +1640,7 @@ test_header (void *cls,
 
   param->num_headers++;
   i = 0;
-  for (pos = connection->headers_received; NULL != pos; pos = pos->next)
+  for (pos = connection->rq.headers_received; NULL != pos; pos = pos->next)
   {
     if (kind != pos->kind)
       continue;
@@ -1720,7 +1706,7 @@ check_argument_match (struct MHD_Connection *connection,
     return false;
   }
   /* also check that the number of headers matches */
-  for (pos = connection->headers_received; NULL != pos; pos = pos->next)
+  for (pos = connection->rq.headers_received; NULL != pos; pos = pos->next)
   {
     if (MHD_GET_ARGUMENT_KIND != pos->kind)
       continue;
@@ -1765,8 +1751,8 @@ check_uri_match (struct MHD_Connection *connection, char 
*uri, size_t uri_len)
   uri_len = daemon->unescape_callback (daemon->unescape_callback_cls,
                                        connection,
                                        uri);
-  if ((uri_len != connection->url_len) ||
-      (0 != memcmp (uri, connection->url, uri_len)))
+  if ((uri_len != connection->rq.url_len) ||
+      (0 != memcmp (uri, connection->rq.url, uri_len)))
   {
 #ifdef HAVE_MESSAGES
     MHD_DLOG (daemon,
@@ -2050,7 +2036,7 @@ digest_auth_check_all_inner (struct MHD_Connection 
*connection,
 
   tmp2_size = 0;
 
-  params = get_rq_dauth_params (connection);
+  params = MHD_get_rq_dauth_params_ (connection);
   if (NULL == params)
     return MHD_DAUTH_WRONG_HEADER;
 
@@ -2336,7 +2322,7 @@ digest_auth_check_all_inner (struct MHD_Connection 
*connection,
 
   /* Get 'uri' */
   digest_init (&da);
-  digest_update_str (&da, connection->method);
+  digest_update_str (&da, connection->rq.method);
   digest_update_with_colon (&da);
 #if 0
   /* TODO: add support for "auth-int" */
@@ -2441,12 +2427,12 @@ digest_auth_check_all_inner (struct MHD_Connection 
*connection,
   /* It was already checked that 'nonce' (including timestamp) was generated
      by MHD. The next check is mostly an overcaution. */
   calculate_nonce (nonce_time,
-                   connection->method,
+                   connection->rq.method,
                    daemon->digest_auth_random,
                    daemon->digest_auth_rand_size,
-                   connection->url,
-                   connection->url_len,
-                   connection->headers_received,
+                   connection->rq.url,
+                   connection->rq.url_len,
+                   connection->rq.headers_received,
                    realm,
                    realm_len,
                    &da,
diff --git a/src/microhttpd/gen_auth.c b/src/microhttpd/gen_auth.c
index 71a1a742..806fe482 100644
--- a/src/microhttpd/gen_auth.c
+++ b/src/microhttpd/gen_auth.c
@@ -40,7 +40,104 @@
 #error This file requires Basic or Digest authentication support
 #endif
 
+/**
+ * Type of authorisation
+ */
+enum MHD_AuthType
+{
+  MHD_AUTHTYPE_NONE = 0,/**< No authorisation, unused */
+  MHD_AUTHTYPE_BASIC,   /**< Basic Authorisation, RFC 7617  */
+  MHD_AUTHTYPE_DIGEST,  /**< Digest Authorisation, RFC 7616 */
+  MHD_AUTHTYPE_UNKNOWN, /**< Unknown/Unsupported authorisation type, unused */
+  MHD_AUTHTYPE_INVALID  /**< Wrong/broken authorisation header, unused */
+};
+
+/**
+ * Find required "Authorization" request header
+ * @param c the connection with request
+ * @param type the type of the authorisation: basic or digest
+ * @param[out] auth_value will be set to the remaining of header value after
+ *                        authorisation token (after "Basic " or "Digest ")
+ * @return true if requested header is found,
+ *         false otherwise
+ */
+static bool
+find_auth_rq_header_ (const struct MHD_Connection *c, enum MHD_AuthType type,
+                      struct _MHD_str_w_len *auth_value)
+{
+  const struct MHD_HTTP_Req_Header *h;
+  const char *token;
+  size_t token_len;
+
+  mhd_assert (MHD_CONNECTION_HEADERS_PROCESSED <= c->state);
+  if (MHD_CONNECTION_HEADERS_PROCESSED > c->state)
+    return false;
+
+#ifdef DAUTH_SUPPORT
+  if (MHD_AUTHTYPE_DIGEST == type)
+  {
+    token = _MHD_AUTH_DIGEST_BASE;
+    token_len = MHD_STATICSTR_LEN_ (_MHD_AUTH_DIGEST_BASE);
+  }
+  else /* combined with the next line */
+#endif /* DAUTH_SUPPORT */
+#ifdef BAUTH_SUPPORT
+  if (MHD_AUTHTYPE_BASIC == type)
+  {
+    token = _MHD_AUTH_BASIC_BASE;
+    token_len = MHD_STATICSTR_LEN_ (_MHD_AUTH_BASIC_BASE);
+  }
+  else /* combined with the next line */
+#endif /* BAUTH_SUPPORT */
+  {
+    assert (0);
+    return false;
+  }
+
+  for (h = c->rq.headers_received; NULL != h; h = h->next)
+  {
+    if (MHD_HEADER_KIND != h->kind)
+      continue;
+    if (MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_AUTHORIZATION) != h->header_size)
+      continue;
+    if (token_len > h->value_size)
+      continue;
+    if (! MHD_str_equal_caseless_bin_n_ (MHD_HTTP_HEADER_AUTHORIZATION,
+                                         h->header,
+                                         MHD_STATICSTR_LEN_ ( \
+                                           MHD_HTTP_HEADER_AUTHORIZATION)))
+      continue;
+    if (! MHD_str_equal_caseless_bin_n_ (h->value, token, token_len))
+      continue;
+    /* Match only if token string is full header value or token is
+     * followed by space or tab
+     * Note: RFC 9110 (and RFC 7234) allows only space character, but
+     * tab is supported here as well for additional flexibility and uniformity
+     * as tabs are supported as separators between parameters.
+     */
+    if ((token_len == h->value_size) ||
+        (' ' == h->value[token_len]) || ('\t'  == h->value[token_len]))
+    {
+      if (token_len != h->value_size)
+      { /* Skip whitespace */
+        auth_value->str = h->value + token_len + 1;
+        auth_value->len = h->value_size - (token_len + 1);
+      }
+      else
+      { /* No whitespace to skip */
+        auth_value->str = h->value + token_len;
+        auth_value->len = h->value_size - token_len;
+      }
+      return true; /* Found a match */
+    }
+  }
+  return false; /* No matching header has been found */
+}
+
+
 #ifdef BAUTH_SUPPORT
+
+
 /**
  * Parse request Authorization header parameters for Basic Authentication
  * @param str the header string, everything after "Basic " substring
@@ -99,6 +196,71 @@ parse_bauth_params (const char *str,
 }
 
 
+/**
+ * Return request's Basic Authorisation parameters.
+ *
+ * Function return result of parsing of the request's "Authorization" header or
+ * returns cached parsing result if the header was already parsed for
+ * the current request.
+ * @param connection the connection to process
+ * @return the pointer to structure with Authentication parameters,
+ *         NULL if no memory in memory pool, if called too early (before
+ *         header has been received) or if no valid Basic Authorisation header
+ *         found.
+ */
+const struct MHD_RqBAuth *
+MHD_get_rq_bauth_params_ (struct MHD_Connection *connection)
+{
+  struct _MHD_str_w_len h_auth_value;
+  struct MHD_RqBAuth *bauth;
+
+  mhd_assert (MHD_CONNECTION_HEADERS_PROCESSED <= connection->state);
+
+  if (connection->rq.bauth_tried)
+    return connection->rq.bauth;
+
+  if (MHD_CONNECTION_HEADERS_PROCESSED > connection->state)
+    return NULL;
+
+  if (! find_auth_rq_header_ (connection, MHD_AUTHTYPE_BASIC, &h_auth_value))
+  {
+    connection->rq.bauth_tried = true;
+    connection->rq.bauth = NULL;
+    return NULL;
+  }
+
+  bauth =
+    (struct MHD_RqBAuth *)
+    MHD_connection_alloc_memory_ (connection, sizeof (struct MHD_RqBAuth));
+
+  if (NULL == bauth)
+  {
+#ifdef HAVE_MESSAGES
+    MHD_DLOG (connection->daemon,
+              _ ("Not enough memory in the connection's pool to allocate " \
+                 "for Basic Authorization header parsing.\n"));
+#endif /* HAVE_MESSAGES */
+    return NULL;
+  }
+
+  memset (bauth, 0, sizeof(struct MHD_RqBAuth));
+  if (parse_bauth_params (h_auth_value.str, h_auth_value.len, bauth))
+    connection->rq.bauth = bauth;
+  else
+  {
+#ifdef HAVE_MESSAGES
+    MHD_DLOG (connection->daemon,
+              _ ("The Basic Authorization client's header has "
+                 "incorrect format.\n"));
+#endif /* HAVE_MESSAGES */
+    connection->rq.bauth = NULL;
+    /* Memory in the pool remains allocated until next request */
+  }
+  connection->rq.bauth_tried = true;
+  return connection->rq.bauth;
+}
+
+
 #endif /* BAUTH_SUPPORT */
 
 #ifdef DAUTH_SUPPORT
@@ -312,213 +474,69 @@ parse_dauth_params (const char *str,
 }
 
 
-#endif /* DAUTH_SUPPORT */
-
-
 /**
- * Parse request "Authorization" header
- * @param c the connection to process
- * @return true if any supported Authorisation scheme were found,
- *         false if no "Authorization" header found, no supported scheme found,
- *         or an error occurred.
+ * Return request's Digest Authorisation parameters.
+ *
+ * Function return result of parsing of the request's "Authorization" header or
+ * returns cached parsing result if the header was already parsed for
+ * the current request.
+ * @param connection the connection to process
+ * @return the pointer to structure with Authentication parameters,
+ *         NULL if no memory in memory pool, if called too early (before
+ *         header has been received) or if no valid Basic Authorisation header
+ *         found.
  */
-_MHD_static_inline bool
-parse_auth_rq_header_ (struct MHD_Connection *c)
+const struct MHD_RqDAuth *
+MHD_get_rq_dauth_params_ (struct MHD_Connection *connection)
 {
-  const char *h; /**< The "Authorization" header */
-  size_t h_len;
-  struct MHD_AuthRqHeader *rq_auth;
-  size_t i;
+  struct _MHD_str_w_len h_auth_value;
+  struct MHD_RqDAuth *dauth;
 
-  mhd_assert (NULL == c->rq_auth);
-  mhd_assert (MHD_CONNECTION_HEADERS_PROCESSED <= c->state);
-  if (MHD_CONNECTION_HEADERS_PROCESSED > c->state)
-    return false;
+  mhd_assert (MHD_CONNECTION_HEADERS_PROCESSED <= connection->state);
 
-  if (MHD_NO ==
-      MHD_lookup_connection_value_n (c, MHD_HEADER_KIND,
-                                     MHD_HTTP_HEADER_AUTHORIZATION,
-                                     MHD_STATICSTR_LEN_ ( \
-                                       MHD_HTTP_HEADER_AUTHORIZATION), &h,
-                                     &h_len))
-  {
-    rq_auth = (struct MHD_AuthRqHeader *)
-              MHD_connection_alloc_memory_ (c,
-                                            sizeof (struct MHD_AuthRqHeader));
-    c->rq_auth = rq_auth;
-    if (NULL != rq_auth)
-    {
-      memset (rq_auth, 0, sizeof(struct MHD_AuthRqHeader));
-      rq_auth->auth_type = MHD_AUTHTYPE_NONE;
-    }
-    return false;
-  }
+  if (connection->rq.dauth_tried)
+    return connection->rq.dauth;
 
-  rq_auth = NULL;
-  i = 0;
-  /* Skip the leading whitespace */
-  while (i < h_len)
-  {
-    const char ch = h[i];
-    if ((' ' != ch) && ('\t' != ch))
-      break;
-    i++;
-  }
-  h += i;
-  h_len -= i;
-
-  if (0 == h_len)
-  { /* The header is an empty string */
-    rq_auth = (struct MHD_AuthRqHeader *)
-              MHD_connection_alloc_memory_ (c,
-                                            sizeof (struct MHD_AuthRqHeader));
-    c->rq_auth = rq_auth;
-    if (NULL != rq_auth)
-    {
-      memset (rq_auth, 0, sizeof(struct MHD_AuthRqHeader));
-      rq_auth->auth_type = MHD_AUTHTYPE_INVALID;
-    }
-    return false;
-  }
+  if (MHD_CONNECTION_HEADERS_PROCESSED > connection->state)
+    return NULL;
 
-#ifdef DAUTH_SUPPORT
-  if (1)
+  if (! find_auth_rq_header_ (connection, MHD_AUTHTYPE_DIGEST, &h_auth_value))
   {
-    static const struct _MHD_cstr_w_len scheme_token =
-      _MHD_S_STR_W_LEN (_MHD_AUTH_DIGEST_BASE);
-
-    if ((scheme_token.len <= h_len) &&
-        MHD_str_equal_caseless_bin_n_ (h, scheme_token.str, scheme_token.len))
-    {
-      i = scheme_token.len;
-      /* RFC 7235 require only space after scheme token */
-      if ( (h_len <= i) ||
-           ((' ' == h[i]) || ('\t' == h[i])) ) /* Actually tab should NOT be 
allowed */
-      { /* Matched Digest authorisation scheme */
-        i++; /* Advance to the next char (even if it is beyond the end of the 
string) */
-
-        rq_auth = (struct MHD_AuthRqHeader *)
-                  MHD_connection_alloc_memory_ (c,
-                                                sizeof (struct 
MHD_AuthRqHeader)
-                                                + sizeof (struct MHD_RqDAuth));
-        c->rq_auth = rq_auth;
-        if (NULL == rq_auth)
-        {
-#ifdef HAVE_MESSAGES
-          MHD_DLOG (c->daemon,
-                    _ ("Failed to allocate memory in connection pool to " \
-                       "process \"" MHD_HTTP_HEADER_AUTHORIZATION "\" " \
-                       "header.\n"));
-#endif /* HAVE_MESSAGES */
-          return false;
-        }
-        memset (rq_auth, 0, sizeof (struct MHD_AuthRqHeader)
-                + sizeof (struct MHD_RqDAuth));
-        rq_auth->params.dauth = (struct MHD_RqDAuth *) (rq_auth + 1);
+    connection->rq.dauth_tried = true;
+    connection->rq.dauth = NULL;
+    return NULL;
+  }
 
-        if (h_len > i)
-        {
-          if (! parse_dauth_params (h + i, h_len - i, rq_auth->params.dauth))
-          {
-            rq_auth->auth_type = MHD_AUTHTYPE_INVALID;
-            return false;
-          }
-        }
+  dauth =
+    (struct MHD_RqDAuth *)
+    MHD_connection_alloc_memory_ (connection, sizeof (struct MHD_RqDAuth));
 
-        rq_auth->auth_type = MHD_AUTHTYPE_DIGEST;
-        return true;
-      }
-    }
-  }
-#endif /* DAUTH_SUPPORT */
-#ifdef BAUTH_SUPPORT
-  if (1)
+  if (NULL == dauth)
   {
-    static const struct _MHD_cstr_w_len scheme_token =
-      _MHD_S_STR_W_LEN (_MHD_AUTH_BASIC_BASE);
-
-    if ((scheme_token.len <= h_len) &&
-        MHD_str_equal_caseless_bin_n_ (h, scheme_token.str, scheme_token.len))
-    {
-      i = scheme_token.len;
-      /* RFC 7235 require only space after scheme token */
-      if ( (h_len <= i) ||
-           ((' ' == h[i]) || ('\t' == h[i])) ) /* Actually tab should NOT be 
allowed */
-      { /* Matched Basic authorisation scheme */
-        i++; /* Advance to the next char (even if it is beyond the end of the 
string) */
-
-        rq_auth = (struct MHD_AuthRqHeader *)
-                  MHD_connection_alloc_memory_ (c,
-                                                sizeof (struct 
MHD_AuthRqHeader)
-                                                + sizeof (struct MHD_RqBAuth));
-        c->rq_auth = rq_auth;
-        if (NULL == rq_auth)
-        {
 #ifdef HAVE_MESSAGES
-          MHD_DLOG (c->daemon,
-                    _ ("Failed to allocate memory in connection pool to " \
-                       "process \"" MHD_HTTP_HEADER_AUTHORIZATION "\" " \
-                       "header.\n"));
+    MHD_DLOG (connection->daemon,
+              _ ("Not enough memory in the connection's pool to allocate " \
+                 "for Digest Authorization header parsing.\n"));
 #endif /* HAVE_MESSAGES */
-          return false;
-        }
-        memset (rq_auth, 0, sizeof (struct MHD_AuthRqHeader)
-                + sizeof (struct MHD_RqBAuth));
-        rq_auth->params.bauth = (struct MHD_RqBAuth *) (rq_auth + 1);
-
-        if (h_len > i)
-        {
-          if (! parse_bauth_params (h + i, h_len - i, rq_auth->params.bauth))
-          {
-            rq_auth->auth_type = MHD_AUTHTYPE_INVALID;
-            return false;
-          }
-        }
-
-        rq_auth->auth_type = MHD_AUTHTYPE_BASIC;
-        return true;
-      }
-    }
+    return NULL;
   }
-#endif /* BAUTH_SUPPORT */
 
-  if (NULL == rq_auth)
-    rq_auth = (struct MHD_AuthRqHeader *)
-              MHD_connection_alloc_memory_ (c,
-                                            sizeof (struct MHD_AuthRqHeader));
-  c->rq_auth = rq_auth;
-  if (NULL != rq_auth)
+  memset (dauth, 0, sizeof(struct MHD_RqDAuth));
+  if (parse_dauth_params (h_auth_value.str, h_auth_value.len, dauth))
+    connection->rq.dauth = dauth;
+  else
   {
-    memset (rq_auth, 0, sizeof(struct MHD_AuthRqHeader));
-    rq_auth->auth_type = MHD_AUTHTYPE_UNKNOWN;
+#ifdef HAVE_MESSAGES
+    MHD_DLOG (connection->daemon,
+              _ ("The Digest Authorization client's header has "
+                 "incorrect format.\n"));
+#endif /* HAVE_MESSAGES */
+    connection->rq.dauth = NULL;
+    /* Memory in the pool remains allocated until next request */
   }
-  return false;
+  connection->rq.dauth_tried = true;
+  return connection->rq.dauth;
 }
 
 
-/**
- * Return request's Authentication type and parameters.
- *
- * Function return result of parsing of the request's "Authorization" header or
- * returns cached parsing result if the header was already parsed for
- * the current request.
- * @param connection the connection to process
- * @return the pointer to structure with Authentication type and parameters,
- *         NULL if no memory in memory pool or if called too early (before
- *         header has been received).
- */
-const struct MHD_AuthRqHeader *
-MHD_get_auth_rq_params_ (struct MHD_Connection *connection)
-{
-  mhd_assert (MHD_CONNECTION_HEADERS_PROCESSED <= connection->state);
-
-  if (NULL != connection->rq_auth)
-    return connection->rq_auth;
-
-  if (MHD_CONNECTION_HEADERS_PROCESSED > connection->state)
-    return NULL;
-
-  parse_auth_rq_header_ (connection);
-
-  return connection->rq_auth;
-}
+#endif /* DAUTH_SUPPORT */
diff --git a/src/microhttpd/gen_auth.h b/src/microhttpd/gen_auth.h
index f6d207e5..9cd84145 100644
--- a/src/microhttpd/gen_auth.h
+++ b/src/microhttpd/gen_auth.h
@@ -33,62 +33,44 @@
 
 struct MHD_Connection; /* Forward declaration to avoid include of the large 
headers */
 
-/**
- * Type of authorisation
- */
-enum MHD_AuthType
-{
-  MHD_AUTHTYPE_NONE = 0,/**< No authorisation */
-  MHD_AUTHTYPE_BASIC,   /**< Basic Authorisation, RFC 7617  */
-  MHD_AUTHTYPE_DIGEST,  /**< Digest Authorisation, RFC 7616 */
-  MHD_AUTHTYPE_UNKNOWN, /**< Unknown/Unsupported authorisation type */
-  MHD_AUTHTYPE_INVALID  /**< Wrong/broken authorisation header */
-};
-
 #ifdef BAUTH_SUPPORT
+
 /* Forward declaration to avoid additional headers inclusion */
 struct MHD_RqBAuth;
-#endif /* BAUTH_SUPPORT */
-#ifdef DAUTH_SUPPORT
-/* Forward declaration to avoid additional headers inclusion */
-struct MHD_RqDAuth;
-#endif /* DAUTH_SUPPORT */
-
 /**
- * Universal Authorisation Request parameters
+ * Return request's Basic Authorisation parameters.
+ *
+ * Function return result of parsing of the request's "Authorization" header or
+ * returns cached parsing result if the header was already parsed for
+ * the current request.
+ * @param connection the connection to process
+ * @return the pointer to structure with Authentication parameters,
+ *         NULL if no memory in memory pool, if called too early (before
+ *         header has been received) or if no valid Basic Authorisation header
+ *         found.
  */
-union MHD_AuthRqParams
-{
-#ifdef BAUTH_SUPPORT
-  struct MHD_RqBAuth *bauth;
+const struct MHD_RqBAuth *
+MHD_get_rq_bauth_params_ (struct MHD_Connection *connection);
+
 #endif /* BAUTH_SUPPORT */
 #ifdef DAUTH_SUPPORT
-  struct MHD_RqDAuth *dauth;
-#endif /* DAUTH_SUPPORT */
-};
-
-/**
- * Request Authentication type and parameters
- */
-struct MHD_AuthRqHeader
-{
-  enum MHD_AuthType auth_type;
-  union MHD_AuthRqParams params;
-};
-
+/* Forward declaration to avoid additional headers inclusion */
+struct MHD_RqDAuth;
 
 /**
- * Return request's Authentication type and parameters.
+ * Return request's Digest Authorisation parameters.
  *
  * Function return result of parsing of the request's "Authorization" header or
  * returns cached parsing result if the header was already parsed for
  * the current request.
  * @param connection the connection to process
- * @return the pointer to structure with Authentication type and parameters,
- *         NULL if no memory in memory pool or if called too early (before
- *         header has been received).
+ * @return the pointer to structure with Authentication parameters,
+ *         NULL if no memory in memory pool, if called too early (before
+ *         header has been received) or if no valid Basic Authorisation header
+ *         found.
  */
-const struct MHD_AuthRqHeader *
-MHD_get_auth_rq_params_ (struct MHD_Connection *connection);
+const struct MHD_RqDAuth *
+MHD_get_rq_dauth_params_ (struct MHD_Connection *connection);
+#endif /* DAUTH_SUPPORT */
 
-#endif /* ! MHD_GET_AUTH_H */
+#endif /* MHD_GET_AUTH_H */
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index fa243a34..e91369ad 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -62,6 +62,10 @@
 #include "mhd_locks.h"
 #include "mhd_sockets.h"
 #include "mhd_itc_types.h"
+#if defined(BAUTH_SUPPORT) || defined(DAUTH_SUPPORT)
+#include "gen_auth.h"
+#endif /* BAUTH_SUPPORT || DAUTH_SUPPORT*/
+
 
 /**
  * Macro to drop 'const' qualifier from pointer without compiler warning.
@@ -264,7 +268,7 @@ struct MHD_NonceNc
    * 'nc' value.
    * This 'nc' value was already used by the client.
    */
-  uint64_t nc;
+  uint32_t nc;
 
   /**
    * Bitmask over the previous 64 nonce counter values (down to to nc-64).
@@ -786,8 +790,6 @@ typedef ssize_t
                      size_t max_bytes);
 
 
-struct MHD_AuthRqHeader; /* Forward declaration only */
-
 /**
  * Ability to use same connection for next request
  */
@@ -917,6 +919,155 @@ enum MHD_HTTP_Method
 } _MHD_FIXED_ENUM;
 
 
+/**
+ * Request-specific values.
+ *
+ * Meaningful for the current request only.
+ */
+struct MHD_Request
+{
+  /**
+   * HTTP version string (i.e. http/1.1).  Allocated
+   * in pool.
+   */
+  const char *version;
+
+  /**
+   * HTTP protocol version as enum.
+   */
+  enum MHD_HTTP_Version http_ver;
+
+  /**
+   * Request method.  Should be GET/POST/etc.  Allocated in pool.
+   */
+  const char *method;
+
+  /**
+   * The request method as enum.
+   */
+  enum MHD_HTTP_Method http_mthd;
+
+  /**
+   * Requested URL (everything after "GET" only).  Allocated
+   * in pool.
+   */
+  const char *url;
+
+  /**
+   * The length of the @a url in characters, not including the terminating 
zero.
+   */
+  size_t url_len;
+
+  /**
+   * Linked list of parsed headers.
+   */
+  struct MHD_HTTP_Req_Header *headers_received;
+
+  /**
+   * Tail of linked list of parsed headers.
+   */
+  struct MHD_HTTP_Req_Header *headers_received_tail;
+
+  /**
+   * Number of bytes we had in the HTTP header, set once we
+   * pass #MHD_CONNECTION_HEADERS_RECEIVED.
+   */
+  size_t header_size;
+
+  /**
+   * How many more bytes of the body do we expect
+   * to read? #MHD_SIZE_UNKNOWN for unknown.
+   */
+  uint64_t remaining_upload_size;
+
+  /**
+   * Are we receiving with chunked encoding?
+   * This will be set to #MHD_YES after we parse the headers and
+   * are processing the body with chunks.
+   * After we are done with the body and we are processing the footers;
+   * once the footers are also done, this will be set to #MHD_NO again
+   * (before the final call to the handler).
+   * It is used only for requests, chunked encoding for response is
+   * indicated by @a rp_props.
+   */
+  bool have_chunked_upload;
+
+  /**
+   * If we are receiving with chunked encoding, where are we right
+   * now?
+   * Set to 0 if we are waiting to receive the chunk size;
+   * otherwise, this is the size of the current chunk.
+   * A value of zero is also used when we're at the end of the chunks.
+   */
+  uint64_t current_chunk_size;
+
+  /**
+   * If we are receiving with chunked encoding, where are we currently
+   * with respect to the current chunk (at what offset / position)?
+   */
+  uint64_t current_chunk_offset;
+
+  /**
+   * We allow the main application to associate some pointer with the
+   * HTTP request, which is passed to each #MHD_AccessHandlerCallback
+   * and some other API calls.  Here is where we store it.  (MHD does
+   * not know or care what it is).
+   */
+  void *client_context;
+
+  /**
+   * Did we ever call the "default_handler" on this request?
+   * This flag determines if we have called the #MHD_OPTION_NOTIFY_COMPLETED
+   * handler when the request finishes.
+   */
+  bool client_aware;
+
+#ifdef BAUTH_SUPPORT
+  /**
+   * Basic Authorization parameters.
+   * The result of Basic Authorization header parsing.
+   * Allocated in the connection's pool.
+   */
+  const struct MHD_RqBAuth *bauth;
+
+  /**
+   * Set to true if current request headers are checked for Basic Authorization
+   */
+  bool bauth_tried;
+#endif /* BAUTH_SUPPORT */
+#ifdef DAUTH_SUPPORT
+  /**
+   * Digest Authorization parameters.
+   * The result of Digest Authorization header parsing.
+   * Allocated in the connection's pool.
+   */
+  const struct MHD_RqDAuth *dauth;
+
+  /**
+   * Set to true if current request headers are checked for Digest 
Authorization
+   */
+  bool dauth_tried;
+#endif /* DAUTH_SUPPORT */
+
+  /**
+   * Last incomplete header line during parsing of headers.
+   * Allocated in pool.  Only valid if state is
+   * either #MHD_CONNECTION_HEADER_PART_RECEIVED or
+   * #MHD_CONNECTION_FOOTER_PART_RECEIVED.
+   */
+  char *last;
+
+  /**
+   * Position after the colon on the last incomplete header
+   * line during parsing of headers.
+   * Allocated in pool.  Only valid if state is
+   * either #MHD_CONNECTION_HEADER_PART_RECEIVED or
+   * #MHD_CONNECTION_FOOTER_PART_RECEIVED.
+   */
+  char *colon;
+};
+
+
 /**
  * Reply-specific properties.
  */
@@ -928,6 +1079,63 @@ struct MHD_Reply_Properties
   bool chunked; /**< Use chunked encoding for reply */
 };
 
+#if defined(_MHD_HAVE_SENDFILE)
+enum MHD_resp_sender_
+{
+  MHD_resp_sender_std = 0,
+  MHD_resp_sender_sendfile
+};
+#endif /* _MHD_HAVE_SENDFILE */
+
+/**
+ * Reply-specific values.
+ *
+ * Meaningful for the current reply only.
+ */
+struct MHD_Reply
+{
+  /**
+   * Response to transmit (initially NULL).
+   */
+  struct MHD_Response *response;
+
+  /**
+   * HTTP response code.  Only valid if response object
+   * is already set.
+   */
+  unsigned int responseCode;
+
+  /**
+   * The "ICY" response.
+   * Reply begins with the SHOUTcast "ICY" line instead of "HTTP".
+   */
+  bool responseIcy;
+
+  /**
+   * Current write position in the actual response
+   * (excluding headers, content only; should be 0
+   * while sending headers).
+   */
+  uint64_t rsp_write_position;
+
+  /**
+   * The copy of iov response.
+   * Valid if iovec response is used.
+   * Updated during send.
+   * Members are allocated in the pool.
+   */
+  struct MHD_iovec_track_ resp_iov;
+
+#if defined(_MHD_HAVE_SENDFILE)
+  enum MHD_resp_sender_ resp_sender;
+#endif /* _MHD_HAVE_SENDFILE */
+
+  /**
+   * Reply-specific properties
+   */
+  struct MHD_Reply_Properties props;
+};
+
 /**
  * State kept for each HTTP request.
  */
@@ -976,19 +1184,14 @@ struct MHD_Connection
   struct MHD_Daemon *daemon;
 
   /**
-   * Linked list of parsed headers.
+   * Request-specific data
    */
-  struct MHD_HTTP_Req_Header *headers_received;
+  struct MHD_Request rq;
 
   /**
-   * Tail of linked list of parsed headers.
+   * Reply-specific data
    */
-  struct MHD_HTTP_Req_Header *headers_received_tail;
-
-  /**
-   * Response to transmit (initially NULL).
-   */
-  struct MHD_Response *response;
+  struct MHD_Reply rp;
 
   /**
    * The memory pool is created whenever we first read from the TCP
@@ -1000,14 +1203,6 @@ struct MHD_Connection
    */
   struct MemoryPool *pool;
 
-  /**
-   * We allow the main application to associate some pointer with the
-   * HTTP request, which is passed to each #MHD_AccessHandlerCallback
-   * and some other API calls.  Here is where we store it.  (MHD does
-   * not know or care what it is).
-   */
-  void *client_context;
-
   /**
    * We allow the main application to associate some pointer with the
    * TCP connection (which may span multiple HTTP requests).  Here is
@@ -1017,47 +1212,6 @@ struct MHD_Connection
    */
   void *socket_context;
 
-  /**
-   * Request method.  Should be GET/POST/etc.  Allocated in pool.
-   */
-  const char *method;
-
-  /**
-   * The request method as enum.
-   */
-  enum MHD_HTTP_Method http_mthd;
-
-  /**
-   * Requested URL (everything after "GET" only).  Allocated
-   * in pool.
-   */
-  const char *url;
-
-  /**
-   * The length of the @a url in characters, not including the terminating 
zero.
-   */
-  size_t url_len;
-
-  /**
-   * HTTP version string (i.e. http/1.1).  Allocated
-   * in pool.
-   */
-  const char *version;
-
-  /**
-   * HTTP protocol version as enum.
-   */
-  enum MHD_HTTP_Version http_ver;
-
-#if defined(BAUTH_SUPPORT) || defined(DAUTH_SUPPORT)
-  /**
-   * Pointer to request authorization structure.
-   * Allocated in pool.
-   */
-  const struct MHD_AuthRqHeader *rq_auth;
-#endif
-
-
   /**
    * Close connection after sending response?
    * Functions may change value from "Unknown" or "KeepAlive" to "Must close",
@@ -1078,23 +1232,6 @@ struct MHD_Connection
    */
   char *write_buffer;
 
-  /**
-   * Last incomplete header line during parsing of headers.
-   * Allocated in pool.  Only valid if state is
-   * either #MHD_CONNECTION_HEADER_PART_RECEIVED or
-   * #MHD_CONNECTION_FOOTER_PART_RECEIVED.
-   */
-  char *last;
-
-  /**
-   * Position after the colon on the last incomplete header
-   * line during parsing of headers.
-   * Allocated in pool.  Only valid if state is
-   * either #MHD_CONNECTION_HEADER_PART_RECEIVED or
-   * #MHD_CONNECTION_FOOTER_PART_RECEIVED.
-   */
-  char *colon;
-
   /**
    * Foreign address (of length @e addr_len).  MALLOCED (not
    * in pool!).
@@ -1138,42 +1275,6 @@ struct MHD_Connection
    */
   size_t write_buffer_append_offset;
 
-  /**
-   * Number of bytes we had in the HTTP header, set once we
-   * pass #MHD_CONNECTION_HEADERS_RECEIVED.
-   */
-  size_t header_size;
-
-  /**
-   * How many more bytes of the body do we expect
-   * to read? #MHD_SIZE_UNKNOWN for unknown.
-   */
-  uint64_t remaining_upload_size;
-
-  /**
-   * Current write position in the actual response
-   * (excluding headers, content only; should be 0
-   * while sending headers).
-   */
-  uint64_t response_write_position;
-
-  /**
-   * The copy of iov response.
-   * Valid if iovec response is used.
-   * Updated during send.
-   * Members are allocated in the pool.
-   */
-  struct MHD_iovec_track_ resp_iov;
-
-
-#if defined(_MHD_HAVE_SENDFILE)
-  enum MHD_resp_sender_
-  {
-    MHD_resp_sender_std = 0,
-    MHD_resp_sender_sendfile
-  } resp_sender;
-#endif /* _MHD_HAVE_SENDFILE */
-
   /**
    * Position in the 100 CONTINUE message that
    * we need to send when receiving http 1.1 requests.
@@ -1198,13 +1299,6 @@ struct MHD_Connection
    */
   uint64_t connection_timeout_ms;
 
-  /**
-   * Did we ever call the "default_handler" on this connection?  (this
-   * flag will determine if we call the #MHD_OPTION_NOTIFY_COMPLETED
-   * handler when the connection closes down).
-   */
-  bool client_aware;
-
   /**
    * Socket for this connection.  Set to #MHD_INVALID_SOCKET if
    * this connection has died (daemon should clean
@@ -1299,50 +1393,6 @@ struct MHD_Connection
    */
   enum MHD_ConnectionEventLoopInfo event_loop_info;
 
-  /**
-   * HTTP response code.  Only valid if response object
-   * is already set.
-   */
-  unsigned int responseCode;
-
-  /**
-   * The "ICY" response.
-   * Reply begins with the SHOUTcast "ICY" line instead of "HTTP".
-   */
-  bool responseIcy;
-
-  /**
-   * Reply-specific properties
-   */
-  struct MHD_Reply_Properties rp_props;
-
-  /**
-   * Are we receiving with chunked encoding?
-   * This will be set to #MHD_YES after we parse the headers and
-   * are processing the body with chunks.
-   * After we are done with the body and we are processing the footers;
-   * once the footers are also done, this will be set to #MHD_NO again
-   * (before the final call to the handler).
-   * It is used only for requests, chunked encoding for response is
-   * indicated by @a rp_props.
-   */
-  bool have_chunked_upload;
-
-  /**
-   * If we are receiving with chunked encoding, where are we right
-   * now?
-   * Set to 0 if we are waiting to receive the chunk size;
-   * otherwise, this is the size of the current chunk.
-   * A value of zero is also used when we're at the end of the chunks.
-   */
-  uint64_t current_chunk_size;
-
-  /**
-   * If we are receiving with chunked encoding, where are we currently
-   * with respect to the current chunk (at what offset / position)?
-   */
-  uint64_t current_chunk_offset;
-
   /**
    * Function used for reading HTTP request stream.
    */
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index ae763b9b..fc1aaa00 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -1159,7 +1159,7 @@ MHD_send_hdr_and_body_ (struct MHD_Connection *connection,
     /* Luckily the type of send function will be used next is known. */
     post_send_setopt (connection,
 #if defined(_MHD_HAVE_SENDFILE)
-                      MHD_resp_sender_std == connection->resp_sender,
+                      MHD_resp_sender_std == connection->rp.resp_sender,
 #else  /* ! _MHD_HAVE_SENDFILE */
                       true,
 #endif /* ! _MHD_HAVE_SENDFILE */
@@ -1179,7 +1179,7 @@ ssize_t
 MHD_send_sendfile_ (struct MHD_Connection *connection)
 {
   ssize_t ret;
-  const int file_fd = connection->response->fd;
+  const int file_fd = connection->rp.response->fd;
   uint64_t left;
   uint64_t offsetu64;
 #ifndef HAVE_SENDFILE64
@@ -1207,18 +1207,19 @@ MHD_send_sendfile_ (struct MHD_Connection *connection)
                             MHD_SENFILE_CHUNK_;
   size_t send_size = 0;
   bool push_data;
-  mhd_assert (MHD_resp_sender_sendfile == connection->resp_sender);
+  mhd_assert (MHD_resp_sender_sendfile == connection->rp.resp_sender);
   mhd_assert (0 == (connection->daemon->options & MHD_USE_TLS));
 
-  offsetu64 = connection->response_write_position
-              + connection->response->fd_off;
+  offsetu64 = connection->rp.rsp_write_position
+              + connection->rp.response->fd_off;
   if (max_off_t < offsetu64)
   {   /* Retry to send with standard 'send()'. */
-    connection->resp_sender = MHD_resp_sender_std;
+    connection->rp.resp_sender = MHD_resp_sender_std;
     return MHD_ERR_AGAIN_;
   }
 
-  left = connection->response->total_size - 
connection->response_write_position;
+  left = connection->rp.response->total_size
+         - connection->rp.rsp_write_position;
 
   if ( (uint64_t) SSIZE_MAX < left)
     left = SSIZE_MAX;
@@ -1274,14 +1275,14 @@ MHD_send_sendfile_ (struct MHD_Connection *connection)
        to fall back to 'SEND'; see also this thread for info on
        odd libc/Linux behavior with sendfile:
        http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */
-    connection->resp_sender = MHD_resp_sender_std;
+    connection->rp.resp_sender = MHD_resp_sender_std;
     return MHD_ERR_AGAIN_;
 #else  /* HAVE_SOLARIS_SENDFILE */
     if ( (EAFNOSUPPORT == err) ||
          (EINVAL == err) ||
          (EOPNOTSUPP == err) )
     {     /* Retry with standard file reader. */
-      connection->resp_sender = MHD_resp_sender_std;
+      connection->rp.resp_sender = MHD_resp_sender_std;
       return MHD_ERR_AGAIN_;
     }
     if ( (ENOTCONN == err) ||
@@ -1323,7 +1324,7 @@ MHD_send_sendfile_ (struct MHD_Connection *connection)
     }
     /* Some unrecoverable error. Possibly file FD is not suitable
      * for sendfile(). Retry with standard send(). */
-    connection->resp_sender = MHD_resp_sender_std;
+    connection->rp.resp_sender = MHD_resp_sender_std;
     return MHD_ERR_AGAIN_;
   }
   mhd_assert (0 < sent_bytes);
@@ -1357,7 +1358,7 @@ MHD_send_sendfile_ (struct MHD_Connection *connection)
         (EOPNOTSUPP == err) )
     {     /* This file FD is not suitable for sendfile().
            * Retry with standard send(). */
-      connection->resp_sender = MHD_resp_sender_std;
+      connection->rp.resp_sender = MHD_resp_sender_std;
       return MHD_ERR_AGAIN_;
     }
     return MHD_ERR_BADF_;   /* Return hard error. */
@@ -1629,9 +1630,9 @@ MHD_send_iovec_ (struct MHD_Connection *connection,
 #endif /* HTTPS_SUPPORT || _MHD_VECT_SEND_NEEDS_SPIPE_SUPPRESSED */
 #endif /* MHD_VECT_SEND */
 
-  mhd_assert (NULL != connection->resp_iov.iov);
-  mhd_assert (NULL != connection->response->data_iov);
-  mhd_assert (connection->resp_iov.cnt > connection->resp_iov.sent);
+  mhd_assert (NULL != connection->rp.resp_iov.iov);
+  mhd_assert (NULL != connection->rp.response->data_iov);
+  mhd_assert (connection->rp.resp_iov.cnt > connection->rp.resp_iov.sent);
 #ifdef MHD_VECT_SEND
 #if defined(HTTPS_SUPPORT) || \
   defined(_MHD_VECT_SEND_NEEDS_SPIPE_SUPPRESSED)
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index cffb859a..d352a804 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -2120,7 +2120,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response 
*response,
   /* hand over socket to application */
   response->upgrade_handler (response->upgrade_handler_cls,
                              connection,
-                             connection->client_context,
+                             connection->rq.client_context,
                              connection->read_buffer,
                              rbo,
 #ifdef HTTPS_SUPPORT
diff --git a/src/microhttpd/test_auth_parse.c b/src/microhttpd/test_auth_parse.c
index 6f7ca5ed..b9507f97 100644
--- a/src/microhttpd/test_auth_parse.c
+++ b/src/microhttpd/test_auth_parse.c
@@ -120,54 +120,6 @@ _mhdErrorExit_func (const char *errDesc, const char 
*funcName, int lineNum)
 
 /* Local replacements implementations */
 
-/**
- * Parameters for function emulation
- */
-struct TestArguments
-{
-  const char *str;
-  size_t len;
-  enum MHD_Result res;
-};
-
-
-_MHD_EXTERN enum MHD_Result
-MHD_lookup_connection_value_n (struct MHD_Connection *connection,
-                               enum MHD_ValueKind kind,
-                               const char *key,
-                               size_t key_size,
-                               const char **value_ptr,
-                               size_t *value_size_ptr)
-{
-  struct TestArguments *args;
-  if (NULL == connection)
-    mhdErrorExitDesc ("The 'connection' parameter is NULL");
-  if (MHD_HEADER_KIND != kind)
-    mhdErrorExitDesc ("Wrong 'kind' parameter");
-  if (NULL == key)
-    mhdErrorExitDesc ("The 'key' parameter is NULL");
-  if (0 != strcmp (key, MHD_HTTP_HEADER_AUTHORIZATION))
-    mhdErrorExitDesc ("Wrong 'key' value");
-  if (MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_AUTHORIZATION) != key_size)
-    mhdErrorExitDesc ("Wrong 'key_size' value");
-  if (NULL == value_ptr)
-    mhdErrorExitDesc ("The 'value_ptr' parameter is NULL");
-  if (NULL == value_size_ptr)
-    mhdErrorExitDesc ("The 'value_size_ptr' parameter is NULL");
-
-  if (NULL == connection->client_context)
-    externalErrorExitDesc ("The 'connection->client_context' value is NULL");
-
-  args = (struct TestArguments *) connection->client_context;
-  if (MHD_NO == args->res)
-    return args->res;
-
-  *value_ptr = args->str;
-  *value_size_ptr = args->len;
-  return args->res;
-}
-
-
 void *
 MHD_connection_alloc_memory_ (struct MHD_Connection *connection,
                               size_t size)
@@ -175,131 +127,285 @@ MHD_connection_alloc_memory_ (struct MHD_Connection 
*connection,
   void *ret;
   if (NULL == connection)
     mhdErrorExitDesc ("'connection' parameter is NULL");
-  /* Use 'socket_context' just as a flag */
-  if (NULL != connection->socket_context)
-    mhdErrorExitDesc ("Unexpected memory allocation, " \
-                      "while previous allocation was not freed");
+  /* Use 'read_buffer' just as a flag */
+  if (NULL != connection->read_buffer)
+  {
+    /* Use 'write_buffer' just as a flag */
+    if (NULL != connection->write_buffer)
+      mhdErrorExitDesc ("Unexpected third memory allocation, " \
+                        "while previous allocations was not freed");
+  }
   /* Just use simple "malloc()" here */
   ret = malloc (size);
   if (NULL == ret)
     externalErrorExit ();
-  connection->socket_context = ret;
+
+  /* Track up to two allocations */
+  if (NULL == connection->read_buffer)
+    connection->read_buffer = (char *) ret;
+  else
+    connection->write_buffer = (char *) ret;
   return ret;
 }
 
 
-_MHD_NORETURN void
+/**
+ * Static variable to avoid additional malloc()/free() pairs
+ */
+static struct MHD_Connection conn;
+
+void
 MHD_DLOG (const struct MHD_Daemon *daemon,
           const char *format,
           ...)
 {
   (void) daemon;
-  fprintf (stderr, "Unexpected call of 'MHD_LOG(), format is '%s'.\n", format);
-  mhdErrorExit ();
+  if (NULL == conn.rq.last)
+  {
+    fprintf (stderr, "Unexpected call of 'MHD_LOG(), format is '%s'.\n",
+             format);
+    fprintf (stderr, "'Authorization' header value: '%s'.\n",
+             (NULL == conn.rq.headers_received) ?
+             "NULL" : (conn.rq.headers_received->value));
+    mhdErrorExit ();
+  }
+  conn.rq.last = NULL; /* Clear the flag */
+  return;
 }
 
 
 /**
  * Static variable to avoid additional malloc()/free() pairs
  */
-static struct MHD_Connection conn;
+static struct MHD_HTTP_Req_Header req_header;
+
+static void
+test_global_init (void)
+{
+  memset (&conn, 0, sizeof(conn));
+  memset (&req_header, 0, sizeof(req_header));
+}
+
 
 /**
- * Create test "Authorization" client header and return result of its parsing.
+ * Add "Authorization" client test header.
  *
- * Function performs basic checking of the parsing result
- * @param use_hdr if set to non-zero value, the test header is added,
- *                if set to zero value, emulated absence "Authorization" client
- *                header
- * @param hdr the test "Authorization" client header string, must be statically
- *                allocated.
+ * @param hdr the pointer to the headr value, must be valid until end of
+ *            checking of this header
  * @param hdr_len the length of the @a hdr
- * @return result of @a hdr parsing (or parsing of header absence if @a use_hdr
- *         is not set), never NULL. Must be free()'ed.
  * @note The function is NOT thread-safe
  */
-static const struct MHD_AuthRqHeader *
-get_AuthRqHeader (int use_hdr, const char *hdr, size_t hdr_len)
+static void
+add_AuthHeader (const char *hdr, size_t hdr_len)
+{
+  if ((NULL != conn.rq.headers_received) ||
+      (NULL != conn.rq.headers_received_tail))
+    externalErrorExitDesc ("Connection's test headers are not empty already");
+  if (NULL != hdr)
+  {
+    /* Skip initial whitespaces, emulate MHD's headers processing */
+    while (' ' == hdr[0] || '\t' == hdr[0])
+    {
+      hdr++;
+      hdr_len--;
+    }
+    req_header.header = MHD_HTTP_HEADER_AUTHORIZATION; /* Static string */
+    req_header.header_size = MHD_STATICSTR_LEN_ 
(MHD_HTTP_HEADER_AUTHORIZATION);
+    req_header.value = hdr;
+    req_header.value_size = hdr_len;
+    req_header.kind = MHD_HEADER_KIND;
+    req_header.prev = NULL;
+    req_header.next = NULL;
+    conn.rq.headers_received = &req_header;
+    conn.rq.headers_received_tail = &req_header;
+  }
+  else
+  {
+    conn.rq.headers_received = NULL;
+    conn.rq.headers_received_tail = NULL;
+  }
+  conn.state = MHD_CONNECTION_FULL_REQ_RECEIVED; /* Should be a typical value 
*/
+}
+
+
+#ifdef BAUTH_SUPPORT
+/**
+ * Parse previously added Basic Authorization client header and return
+ * result of the parsing.
+ *
+ * Function performs basic checking of the parsing result
+ * @return result of header parsing
+ * @note The function is NOT thread-safe
+ */
+static const struct MHD_RqBAuth *
+get_BAuthRqParams (void)
 {
-  const struct MHD_AuthRqHeader *res1;
-  const struct MHD_AuthRqHeader *res2;
-  static struct TestArguments test_args;
-  if (NULL != conn.socket_context)
-    mhdErrorExitDesc ("Memory was not freed in previous check cycle");
-  test_args.res = use_hdr ? MHD_YES : MHD_NO;
-  test_args.str = hdr;
-  test_args.len = hdr_len;
-  memset (&conn, 0, sizeof (conn));
+  const struct MHD_RqBAuth *res1;
+  const struct MHD_RqBAuth *res2;
   /* Store pointer in some member unused in this test */
-  conn.client_context = &test_args;
-  conn.state = MHD_CONNECTION_FULL_REQ_RECEIVED; /* Should be typical value */
-  res1 = MHD_get_auth_rq_params_ (&conn);
-  if (NULL == res1)
-    mhdErrorExitDesc ("MHD_get_auth_rq_params_() returned NULL");
-  res2 = MHD_get_auth_rq_params_ (&conn);
+  res1 = MHD_get_rq_bauth_params_ (&conn);
+  if (! conn.rq.bauth_tried)
+    mhdErrorExitDesc ("'rq.bauth_tried' is not set");
+  res2 = MHD_get_rq_bauth_params_ (&conn);
   if (res1 != res2)
-    mhdErrorExitDesc ("MHD_get_auth_rq_params_() returned another pointer 
when" \
-                      "called for the second time");
+    mhdErrorExitDesc ("MHD_get_rq_bauth_params_() returned another pointer " \
+                      "when called for the second time");
   return res2;
 }
 
 
+#endif /* BAUTH_SUPPORT */
+
+#ifdef DAUTH_SUPPORT
+/**
+ * Parse previously added Digest Authorization client header and return
+ * result of the parsing.
+ *
+ * Function performs basic checking of the parsing result
+ * @return result of header parsing
+ * @note The function is NOT thread-safe
+ */
+static const struct MHD_RqDAuth *
+get_DAuthRqParams (void)
+{
+  const struct MHD_RqDAuth *res1;
+  const struct MHD_RqDAuth *res2;
+  /* Store pointer in some member unused in this test */
+  res1 = MHD_get_rq_dauth_params_ (&conn);
+  if (! conn.rq.dauth_tried)
+    mhdErrorExitDesc ("'rq.dauth_tried' is not set");
+  res2 = MHD_get_rq_dauth_params_ (&conn);
+  if (res1 != res2)
+    mhdErrorExitDesc ("MHD_get_rq_bauth_params_() returned another pointer " \
+                      "when called for the second time");
+  return res2;
+}
+
+
+#endif /* DAUTH_SUPPORT */
+
+
 static void
-free_AuthRqHeader (void)
+clean_AuthHeaders (void)
 {
-  if (conn.socket_context != conn.rq_auth)
+  conn.state = MHD_CONNECTION_INIT;
+  free (conn.read_buffer);
+  free (conn.write_buffer);
+
+#ifdef BAUTH_SUPPORT
+  conn.rq.bauth_tried = false;
+#endif /* BAUTH_SUPPORT */
+#ifdef DAUTH_SUPPORT
+  conn.rq.dauth_tried = false;
+#endif /* BAUTH_SUPPORT */
+
+#ifdef BAUTH_SUPPORT
+  if ((NULL != conn.rq.bauth) &&
+      (conn.read_buffer != (const char *) conn.rq.bauth) &&
+      (conn.write_buffer != (const char *) conn.rq.bauth))
+    externalErrorExitDesc ("Memory allocation is not tracked as it should be");
+  conn.rq.bauth = NULL;
+#endif /* BAUTH_SUPPORT */
+#ifdef DAUTH_SUPPORT
+  if ((NULL != conn.rq.dauth) &&
+      (conn.read_buffer != (const char *) conn.rq.dauth) &&
+      (conn.write_buffer != (const char *) conn.rq.dauth))
     externalErrorExitDesc ("Memory allocation is not tracked as it should be");
+  conn.rq.dauth = NULL;
+#endif /* BAUTH_SUPPORT */
 
-  if (NULL != conn.rq_auth)
-    free (conn.socket_context);
-  conn.rq_auth = NULL;
-  conn.socket_context = NULL;
+  conn.rq.headers_received = NULL;
+  conn.rq.headers_received_tail = NULL;
+
+  conn.read_buffer = NULL;
+  conn.write_buffer = NULL;
+  conn.rq.last = NULL;
 }
 
 
-static const char *
-get_auth_type_str (enum MHD_AuthType type)
+enum MHD_TestAuthType
 {
-  switch (type)
-  {
-  case MHD_AUTHTYPE_NONE:
-    return "No authorisation";
-  case MHD_AUTHTYPE_BASIC:
-    return "Basic Authorisation";
-  case MHD_AUTHTYPE_DIGEST:
-    return "Digest Authorisation";
-  case MHD_AUTHTYPE_UNKNOWN:
-    return "Unknown/Unsupported authorisation";
-  case MHD_AUTHTYPE_INVALID:
-    return "Wrong/broken authorisation header";
-  default:
-    mhdErrorExitDesc ("Wrong 'enum MHD_AuthType' value");
-  }
-  return "Wrong 'enum MHD_AuthType' value"; /* Unreachable code */
-}
+  MHD_TEST_AUTHTYPE_NONE,
+  MHD_TEST_AUTHTYPE_BASIC,
+  MHD_TEST_AUTHTYPE_DIGEST,
+};
 
 
-/* return zero if succeed, 1 otherwise */
+/* return zero if succeed, non-zero otherwise */
 static unsigned int
-expect_result_type_n (int use_hdr, const char *hdr, size_t hdr_len,
-                      const enum MHD_AuthType expected_type,
+expect_result_type_n (const char *hdr, size_t hdr_len,
+                      const enum MHD_TestAuthType expected_type,
+                      int expect_log,
                       unsigned int line_num)
 {
-  const struct MHD_AuthRqHeader *h;
+  static char marker1[] = "Expected log call";
   unsigned int ret;
 
-  h = get_AuthRqHeader (use_hdr, hdr, hdr_len);
-  mhd_assert (NULL != h);
-  if (expected_type == h->auth_type)
-    ret = 0;
+  ret = 0;
+  add_AuthHeader (hdr, hdr_len);
+  if (expect_log)
+    conn.rq.last = marker1; /* Use like a flag */
+  else
+    conn.rq.last = NULL;
+#ifdef BAUTH_SUPPORT
+  if (MHD_TEST_AUTHTYPE_BASIC == expected_type)
+  {
+    if (NULL == get_BAuthRqParams ())
+    {
+      fprintf (stderr,
+               "'Authorization' header parsing FAILED:\n"
+               "Basic Authorization was not found, while it should be.\n");
+      ret++;
+    }
+  }
+  else
+#endif /* BAUTH_SUPPORT */
+#ifdef DAUTH_SUPPORT
+  if (MHD_TEST_AUTHTYPE_DIGEST == expected_type)
+  {
+    if (NULL == get_DAuthRqParams ())
+    {
+      fprintf (stderr,
+               "'Authorization' header parsing FAILED:\n"
+               "Digest Authorization was not found, while it should be.\n");
+      ret++;
+    }
+  }
   else
+#endif /* BAUTH_SUPPORT */
+  {
+#ifdef BAUTH_SUPPORT
+    if (NULL != get_BAuthRqParams ())
+    {
+      fprintf (stderr,
+               "'Authorization' header parsing FAILED:\n"
+               "Found Basic Authorization, while it should not be.\n");
+      ret++;
+    }
+#endif /* BAUTH_SUPPORT */
+#ifdef DAUTH_SUPPORT
+    if (NULL != get_DAuthRqParams ())
+    {
+      fprintf (stderr,
+               "'Authorization' header parsing FAILED:\n"
+               "Found Digest Authorization, while it should not be.\n");
+      ret++;
+    }
+#endif /* DAUTH_SUPPORT */
+  }
+#if defined(BAUTH_SUPPORT) && defined(DAUTH_SUPPORT)
+  if (conn.rq.last)
   {
     fprintf (stderr,
-             "'Authorization' header parsing FAILED:\n"
-             "Wrong type:\tRESULT: %s\tEXPECTED: %s\n",
-             get_auth_type_str (h->auth_type),
-             get_auth_type_str (expected_type));
-    if (! use_hdr)
+             "'Authorization' header parsing ERROR:\n"
+             "Log function must be called, but it was not.\n");
+    ret++;
+  }
+#endif /* BAUTH_SUPPORT && DAUTH_SUPPORT */
+
+  if (ret)
+  {
+    if (NULL == hdr)
       fprintf (stderr,
                "Input: Absence of 'Authorization' header.\n");
     else if (0 == hdr_len)
@@ -312,30 +418,14 @@ expect_result_type_n (int use_hdr, const char *hdr, 
size_t hdr_len,
              "The check is at line: %u\n\n", line_num);
     ret = 1;
   }
-  free_AuthRqHeader ();
+  clean_AuthHeaders ();
 
   return ret;
 }
 
 
-#define expect_result_type(u,h,t) \
-    expect_result_type_n(u,h,MHD_STATICSTR_LEN_(h),t,__LINE__)
-
-
-#ifdef BAUTH_SUPPORT
-#define EXPECT_TYPE_FOR_BASIC_AUTH MHD_AUTHTYPE_BASIC
-#define EXPECT_TYPE_FOR_BASIC_INVLD MHD_AUTHTYPE_INVALID
-#else  /* ! BAUTH_SUPPORT */
-#define EXPECT_TYPE_FOR_BASIC_AUTH MHD_AUTHTYPE_UNKNOWN
-#define EXPECT_TYPE_FOR_BASIC_INVLD MHD_AUTHTYPE_UNKNOWN
-#endif /* ! BAUTH_SUPPORT */
-#ifdef DAUTH_SUPPORT
-#define EXPECT_TYPE_FOR_DIGEST_AUTH MHD_AUTHTYPE_DIGEST
-#define EXPECT_TYPE_FOR_DIGEST_INVLD MHD_AUTHTYPE_INVALID
-#else  /* ! DAUTH_SUPPORT */
-#define EXPECT_TYPE_FOR_DIGEST_AUTH MHD_AUTHTYPE_UNKNOWN
-#define EXPECT_TYPE_FOR_DIGEST_INVLD MHD_AUTHTYPE_UNKNOWN
-#endif /* ! DAUTH_SUPPORT */
+#define expect_result_type(h,t,l) \
+    expect_result_type_n(h,MHD_STATICSTR_LEN_(h),t,l,__LINE__)
 
 
 static unsigned int
@@ -343,378 +433,378 @@ check_type (void)
 {
   unsigned int r = 0; /**< The number of errors */
 
-  r += expect_result_type (0, "", MHD_AUTHTYPE_NONE);
-
-  r += expect_result_type (1, "", MHD_AUTHTYPE_INVALID);
-  r += expect_result_type (1, " ", MHD_AUTHTYPE_INVALID);
-  r += expect_result_type (1, "    ", MHD_AUTHTYPE_INVALID);
-  r += expect_result_type (1, "\t", MHD_AUTHTYPE_INVALID);
-  r += expect_result_type (1, " \t", MHD_AUTHTYPE_INVALID);
-  r += expect_result_type (1, "\t ", MHD_AUTHTYPE_INVALID);
-  r += expect_result_type (1, "\t \t", MHD_AUTHTYPE_INVALID);
-  r += expect_result_type (1, " \t ", MHD_AUTHTYPE_INVALID);
-  r += expect_result_type (1, " \t \t", MHD_AUTHTYPE_INVALID);
-  r += expect_result_type (1, "\t \t ", MHD_AUTHTYPE_INVALID);
-
-  r += expect_result_type (1, "Basic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, " Basic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\tBasic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t Basic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, " \tBasic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "    Basic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t\t\tBasic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t\t  \tBasic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t\t  \t Basic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "Basic ", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "Basic \t", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "Basic \t ", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "Basic 123", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "Basic \t123", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "Basic  abc ", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "bAsIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, " bAsIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\tbAsIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t bAsIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, " \tbAsIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "    bAsIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t\t\tbAsIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t\t  \tbAsIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t\t  \t bAsIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "bAsIC ", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "bAsIC \t", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "bAsIC \t ", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "bAsIC 123", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "bAsIC \t123", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "bAsIC  abc ", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "basic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, " basic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\tbasic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t basic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, " \tbasic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "    basic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t\t\tbasic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t\t  \tbasic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t\t  \t basic", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "basic ", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "basic \t", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "basic \t ", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "basic 123", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "basic \t123", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "basic  abc ", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "BASIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, " BASIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\tBASIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t BASIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, " \tBASIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "    BASIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t\t\tBASIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t\t  \tBASIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "\t\t  \t BASIC", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "BASIC ", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "BASIC \t", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "BASIC \t ", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "BASIC 123", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "BASIC \t123", EXPECT_TYPE_FOR_BASIC_AUTH);
-  r += expect_result_type (1, "BASIC  abc ", EXPECT_TYPE_FOR_BASIC_AUTH);
+  r += expect_result_type_n (NULL, 0, MHD_TEST_AUTHTYPE_NONE, 0, __LINE__);
+
+  r += expect_result_type ("", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("    ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\t", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" \t", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\t ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\t \t", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" \t ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" \t \t", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\t \t ", MHD_TEST_AUTHTYPE_NONE, 0);
+
+  r += expect_result_type ("Basic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type (" Basic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\tBasic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t Basic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type (" \tBasic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("    Basic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t\t\tBasic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t\t  \tBasic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t\t  \t Basic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("Basic ", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("Basic \t", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("Basic \t ", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("Basic 123", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("Basic \t123", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("Basic  abc ", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("bAsIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type (" bAsIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\tbAsIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t bAsIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type (" \tbAsIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("    bAsIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t\t\tbAsIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t\t  \tbAsIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t\t  \t bAsIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("bAsIC ", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("bAsIC \t", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("bAsIC \t ", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("bAsIC 123", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("bAsIC \t123", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("bAsIC  abc ", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("basic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type (" basic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\tbasic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t basic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type (" \tbasic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("    basic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t\t\tbasic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t\t  \tbasic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t\t  \t basic", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("basic ", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("basic \t", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("basic \t ", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("basic 123", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("basic \t123", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("basic  abc ", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("BASIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type (" BASIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\tBASIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t BASIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type (" \tBASIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("    BASIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t\t\tBASIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t\t  \tBASIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("\t\t  \t BASIC", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("BASIC ", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("BASIC \t", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("BASIC \t ", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("BASIC 123", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("BASIC \t123", MHD_TEST_AUTHTYPE_BASIC, 0);
+  r += expect_result_type ("BASIC  abc ", MHD_TEST_AUTHTYPE_BASIC, 0);
   /* Only single token is allowed for 'Basic' Authorization */
-  r += expect_result_type (1, "Basic a b", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic a\tb", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic a\tb", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic abc1 b", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic c abc1", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic c abc1 ", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic c abc1\t", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic c\tabc1\t", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic c abc1 b", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic zyx, b", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic zyx,b", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic zyx ,b", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic zyx;b", EXPECT_TYPE_FOR_BASIC_INVLD);
-  r += expect_result_type (1, "Basic zyx; b", EXPECT_TYPE_FOR_BASIC_INVLD);
-
-  r += expect_result_type (1, "Basic2", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, " Basic2", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, " Basic2 ", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "\tBasic2", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "\t Basic2", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, " \tBasic2", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "    Basic2", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "\t\t\tBasic2", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "\t\t  \tBasic2", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "\t\t  \t Basic2", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "Basic2 ", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "Basic2 \t", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "Basic2 \t ", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "Basic2 123", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "Basic2 \t123", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "Basic2  abc ", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "BasicBasic", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, " BasicBasic", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "\tBasicBasic", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "\t BasicBasic", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, " \tBasicBasic", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "BasicBasic ", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "BasicBasic \t", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "BasicBasic \t\t", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "BasicDigest", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, " BasicDigest", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "BasicDigest ", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "Basic\0", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "\0" "Basic", MHD_AUTHTYPE_UNKNOWN);
-
-  r += expect_result_type (1, "Digest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, " Digest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\tDigest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t Digest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, " \tDigest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "    Digest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t\t\tDigest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t\t  \tDigest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t\t  \t Digest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest \t", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest \t ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\tDigest ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "  Digest \t", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t \tDigest \t ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-
-  r += expect_result_type (1, "digEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, " digEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\tdigEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t digEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, " \tdigEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "    digEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t\t\tdigEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t\t  \tdigEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t\t  \t digEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "digEST ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "digEST \t", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "digEST \t ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\tdigEST ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "  digEST \t", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t \tdigEST \t ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "digest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, " digest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\tdigest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t digest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, " \tdigest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "    digest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t\t\tdigest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t\t  \tdigest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t\t  \t digest", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "digest ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "digest \t", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "digest \t ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\tdigest ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "  digest \t", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t \tdigest \t ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "DIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, " DIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\tDIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t DIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, " \tDIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "    DIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t\t\tDIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t\t  \tDIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t\t  \t DIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "DIGEST ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "DIGEST \t", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "DIGEST \t ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\tDIGEST ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "  DIGEST \t", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "\t \tDIGEST \t ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ,", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ,\t", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ,  ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest   ,  ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ,\t, ,\t, ,\t, ,", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ,\t,\t,\t,\t,\t,\t,", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest a=b", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest a=\"b\"", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest nc=1", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest nc=\"1\"", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest a=b ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest a=\"b\" ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest nc=1 ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest nc=\"1\" ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest a = b", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest a\t=\t\"b\"", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest nc =1", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest nc= \"1\"", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest a=\tb ", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest a = \"b\" ", 
EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest nc\t\t\t= 1 ", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest nc   =\t\t\t\"1\" ", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest nc =1,,,,", EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest nc =1  ,,,,", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ,,,,nc= \"1 \"", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ,,,,  nc= \" 1\"", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ,,,, nc= \"1\",,,,", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ,,,, nc= \"1\"  ,,,,", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ,,,, nc= \"1\"  ,,,,", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ,,,, nc= \"1\"  ,,,,", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-  r += expect_result_type (1, "Digest ,,,, nc= \"1\"  ,,,,,", \
-                           EXPECT_TYPE_FOR_DIGEST_AUTH);
-
-  r += expect_result_type (1, "Digest nc", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest   nc", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc  ", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc  ,", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc  , ", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest \tnc\t  ", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest \tnc\t  ", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc,", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc,uri", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=1,uri", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=1,uri   ", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=1,uri,", 
EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=1, uri,", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=1,uri   ,", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=1,uri   , ", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
+  r += expect_result_type ("Basic a b", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic a\tb", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic a\tb", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic abc1 b", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic c abc1", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic c abc1 ", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic c abc1\t", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic c\tabc1\t", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic c abc1 b", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic zyx, b", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic zyx,b", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic zyx ,b", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic zyx;b", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Basic zyx; b", MHD_TEST_AUTHTYPE_NONE, 1);
+
+  r += expect_result_type ("Basic2", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" Basic2", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" Basic2 ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\tBasic2", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\t Basic2", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" \tBasic2", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("    Basic2", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\t\t\tBasic2", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\t\t  \tBasic2", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\t\t  \t Basic2", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("Basic2 ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("Basic2 \t", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("Basic2 \t ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("Basic2 123", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("Basic2 \t123", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("Basic2  abc ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("BasicBasic", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" BasicBasic", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\tBasicBasic", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\t BasicBasic", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" \tBasicBasic", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("BasicBasic ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("BasicBasic \t", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("BasicBasic \t\t", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("BasicDigest", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" BasicDigest", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("BasicDigest ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("Basic\0", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\0" "Basic", MHD_TEST_AUTHTYPE_NONE, 0);
+
+  r += expect_result_type ("Digest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type (" Digest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\tDigest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t Digest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type (" \tDigest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("    Digest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t\t\tDigest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t\t  \tDigest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t\t  \t Digest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest \t", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest \t ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\tDigest ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("  Digest \t", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t \tDigest \t ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+
+  r += expect_result_type ("digEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type (" digEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\tdigEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t digEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type (" \tdigEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("    digEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t\t\tdigEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t\t  \tdigEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t\t  \t digEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("digEST ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("digEST \t", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("digEST \t ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\tdigEST ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("  digEST \t", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t \tdigEST \t ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("digest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type (" digest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\tdigest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t digest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type (" \tdigest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("    digest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t\t\tdigest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t\t  \tdigest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t\t  \t digest", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("digest ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("digest \t", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("digest \t ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\tdigest ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("  digest \t", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t \tdigest \t ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("DIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type (" DIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\tDIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t DIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type (" \tDIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("    DIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t\t\tDIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t\t  \tDIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t\t  \t DIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("DIGEST ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("DIGEST \t", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("DIGEST \t ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\tDIGEST ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("  DIGEST \t", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("\t \tDIGEST \t ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ,", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ,\t", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ,  ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest   ,  ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ,\t, ,\t, ,\t, ,", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ,\t,\t,\t,\t,\t,\t,", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest a=b", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest a=\"b\"", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest nc=1", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest nc=\"1\"", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest a=b ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest a=\"b\" ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest nc=1 ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest nc=\"1\" ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest a = b", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest a\t=\t\"b\"", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest nc =1", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest nc= \"1\"", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest a=\tb ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest a = \"b\" ", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest nc\t\t\t= 1 ", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest nc   =\t\t\t\"1\" ", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest nc =1,,,,", MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest nc =1  ,,,,", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ,,,,nc= \"1 \"", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ,,,,  nc= \" 1\"", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ,,,, nc= \"1\",,,,", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ,,,, nc= \"1\"  ,,,,", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ,,,, nc= \"1\"  ,,,,", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ,,,, nc= \"1\"  ,,,,", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+  r += expect_result_type ("Digest ,,,, nc= \"1\"  ,,,,,", \
+                           MHD_TEST_AUTHTYPE_DIGEST, 0);
+
+  r += expect_result_type ("Digest nc", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest   nc", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc  ", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc  ,", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc  , ", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest \tnc\t  ", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest \tnc\t  ", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc,", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc,uri", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=1,uri", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=1,uri   ", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=1,uri,", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=1, uri,", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=1,uri   ,", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=1,uri   , ", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
   /* Binary zero */
-  r += expect_result_type (1, "Digest nc=1\0", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=1\0" " ", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=1\t\0", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=\0" "1", 
EXPECT_TYPE_FOR_DIGEST_INVLD);
+  r += expect_result_type ("Digest nc=1\0", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=1\0" " ", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=1\t\0", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=\0" "1", MHD_TEST_AUTHTYPE_NONE, 1);
   /* Semicolon */
-  r += expect_result_type (1, "Digest nc=1;", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=1; ", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=;1", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc;=1", EXPECT_TYPE_FOR_DIGEST_INVLD);
+  r += expect_result_type ("Digest nc=1;", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=1; ", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=;1", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc;=1", MHD_TEST_AUTHTYPE_NONE, 1);
   /* The equal sign alone */
-  r += expect_result_type (1, "Digest =", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest   =", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest   =  ", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest ,=", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest , =", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest ,= ", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest , = ", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=1,=", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=1, =", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=bar,=", 
EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=bar, =", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
+  r += expect_result_type ("Digest =", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest   =", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest   =  ", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest ,=", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest , =", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest ,= ", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest , = ", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=1,=", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=1, =", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=bar,=", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=bar, =", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
   /* Unclosed quotation */
-  r += expect_result_type (1, "Digest nc=\"", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=\"abc", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=\"   ", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=\"abc   ", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=\"   abc", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=\"   abc", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=\"\\", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=\"\\\"", 
EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=\"  \\\"", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=\"\\\"  ", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=\"  \\\"  ", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc=\"\\\"\\\"\\\"\\\"", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc= \"", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc= \"abc", 
EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc= \"   ", 
EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc= \"abc   ", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc= \"   abc", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc= \"   abc", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc= \"\\", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc= \"\\\"", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc= \"  \\\"", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc= \"\\\"  ", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc= \"  \\\"  ", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest nc= \"\\\"\\\"\\\"\\\"", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\"", EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\"bar", 
EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\"   ", 
EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\"bar   ", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\"   bar", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\"   bar", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo= \"   bar", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\",   bar", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\"   bar,", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\"\\\"", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\"  \\\"", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\"\\\"  ", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\"  \\\"  ", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest foo=\"\\\"\\\"\\\"\\\"", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
+  r += expect_result_type ("Digest nc=\"", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=\"abc", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=\"   ", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=\"abc   ", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=\"   abc", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=\"   abc", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=\"\\", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=\"\\\"", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=\"  \\\"", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=\"\\\"  ", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=\"  \\\"  ", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc=\"\\\"\\\"\\\"\\\"", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc= \"", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc= \"abc", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc= \"   ", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc= \"abc   ", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc= \"   abc", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc= \"   abc", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc= \"\\", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc= \"\\\"", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc= \"  \\\"", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc= \"\\\"  ", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc= \"  \\\"  ", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest nc= \"\\\"\\\"\\\"\\\"", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\"", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\"bar", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\"   ", MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\"bar   ", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\"   bar", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\"   bar", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo= \"   bar", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\",   bar", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\"   bar,", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\"\\\"", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\"  \\\"", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\"\\\"  ", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\"  \\\"  ", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest foo=\"\\\"\\\"\\\"\\\"", \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
   /* Full set of parameters with semicolon inside */
-  r += expect_result_type (1, "Digest username=\"test@example.com\", " \
+  r += expect_result_type ("Digest username=\"test@example.com\", " \
                            "realm=\"users@example.com\", 
nonce=\"32141232413abcde\", " \
                            "uri=\"/example\", qop=auth, nc=00000001; 
cnonce=\"0a4f113b\", " \
                            "response=\"6629fae49393a05397450978507c4ef1\", " \
                            "opaque=\"sadfljk32sdaf\"", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest username=\"test@example.com\", " \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest username=\"test@example.com\", " \
                            "realm=\"users@example.com\", 
nonce=\"32141232413abcde\", " \
                            "uri=\"/example\", qop=auth, 
nc=00000001;cnonce=\"0a4f113b\", " \
                            "response=\"6629fae49393a05397450978507c4ef1\", " \
                            "opaque=\"sadfljk32sdaf\"", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-  r += expect_result_type (1, "Digest username;=\"test@example.com\", " \
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+  r += expect_result_type ("Digest username;=\"test@example.com\", " \
                            "realm=\"users@example.com\", 
nonce=\"32141232413abcde\", " \
                            "uri=\"/example\", qop=auth, nc=00000001, 
cnonce=\"0a4f113b\", " \
                            "response=\"6629fae49393a05397450978507c4ef1\", " \
                            "opaque=\"sadfljk32sdaf\"", \
-                           EXPECT_TYPE_FOR_DIGEST_INVLD);
-
-  r += expect_result_type (1, "Digest2", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "2Digest", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "Digest" "a", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "a" "Digest", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, " Digest2", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, " 2Digest", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, " Digest" "a", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, " a" "Digest", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "Digest2 ", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "2Digest ", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "Digest" "a", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "a" "Digest ", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "DigestBasic", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "DigestBasic ", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, " DigestBasic", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "DigestBasic" "a", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "Digest" "\0", MHD_AUTHTYPE_UNKNOWN);
-  r += expect_result_type (1, "\0" "Digest", MHD_AUTHTYPE_UNKNOWN);
+                           MHD_TEST_AUTHTYPE_NONE, 1);
+
+  r += expect_result_type ("Digest2", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("2Digest", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("Digest" "a", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("a" "Digest", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" Digest2", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" 2Digest", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" Digest" "a", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" a" "Digest", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("Digest2 ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("2Digest ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("Digest" "a", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("a" "Digest ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("DigestBasic", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("DigestBasic ", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type (" DigestBasic", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("DigestBasic" "a", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("Digest" "\0", MHD_TEST_AUTHTYPE_NONE, 0);
+  r += expect_result_type ("\0" "Digest", MHD_TEST_AUTHTYPE_NONE, 0);
   return r;
 }
 
@@ -727,51 +817,39 @@ expect_basic_n (const char *hdr, size_t hdr_len,
                 const char *tkn, size_t tkn_len,
                 unsigned int line_num)
 {
-  const struct MHD_AuthRqHeader *h;
+  const struct MHD_RqBAuth *h;
   unsigned int ret;
 
   mhd_assert (NULL != hdr);
   mhd_assert (0 != hdr_len);
 
-  h = get_AuthRqHeader (1, hdr, hdr_len);
-  mhd_assert (NULL != h);
-  if (MHD_AUTHTYPE_BASIC != h->auth_type)
-  {
+  add_AuthHeader (hdr, hdr_len);
+  h = get_BAuthRqParams ();
+  if (NULL == h)
+    mhdErrorExitDesc ("'MHD_get_rq_bauth_params_()' returned NULL");
+  ret = 1;
+  if (tkn_len != h->token68.len)
     fprintf (stderr,
              "'Authorization' header parsing FAILED:\n"
-             "Wrong type:\tRESULT: %s\tEXPECTED: %s\n",
-             get_auth_type_str (h->auth_type),
-             get_auth_type_str (MHD_AUTHTYPE_BASIC));
-    ret = 1;
-  }
+             "Wrong token length:\tRESULT[%u]: %.*s\tEXPECTED[%u]: %.*s\n",
+             (unsigned) h->token68.len,
+             (int) h->token68.len,
+             h->token68.str ?
+             h->token68.str : "(NULL)",
+             (unsigned) tkn_len, (int) tkn_len, tkn ? tkn : "(NULL)");
+  else if ( ((NULL == tkn) != (NULL == h->token68.str)) ||
+            ((NULL != tkn) &&
+             (0 != memcmp (tkn, h->token68.str, tkn_len))) )
+    fprintf (stderr,
+             "'Authorization' header parsing FAILED:\n"
+             "Wrong token string:\tRESULT[%u]: %.*s\tEXPECTED[%u]: %.*s\n",
+             (unsigned) h->token68.len,
+             (int) h->token68.len,
+             h->token68.str ?
+             h->token68.str : "(NULL)",
+             (unsigned) tkn_len, (int) tkn_len, tkn ? tkn : "(NULL)");
   else
-  {
-    if (NULL == h->params.bauth)
-      mhdErrorExitDesc ("'params.bauth' pointer is NULL");
-    ret = 1;
-    if (tkn_len != h->params.bauth->token68.len)
-      fprintf (stderr,
-               "'Authorization' header parsing FAILED:\n"
-               "Wrong token length:\tRESULT[%u]: %.*s\tEXPECTED[%u]: %.*s\n",
-               (unsigned) h->params.bauth->token68.len,
-               (int) h->params.bauth->token68.len,
-               h->params.bauth->token68.str ?
-               h->params.bauth->token68.str : "(NULL)",
-               (unsigned) tkn_len, (int) tkn_len, tkn ? tkn : "(NULL)");
-    else if ( ((NULL == tkn) != (NULL == h->params.bauth->token68.str)) ||
-              ((NULL != tkn) &&
-               (0 != memcmp (tkn, h->params.bauth->token68.str, tkn_len))) )
-      fprintf (stderr,
-               "'Authorization' header parsing FAILED:\n"
-               "Wrong token string:\tRESULT[%u]: %.*s\tEXPECTED[%u]: %.*s\n",
-               (unsigned) h->params.bauth->token68.len,
-               (int) h->params.bauth->token68.len,
-               h->params.bauth->token68.str ?
-               h->params.bauth->token68.str : "(NULL)",
-               (unsigned) tkn_len, (int) tkn_len, tkn ? tkn : "(NULL)");
-    else
-      ret = 0;
-  }
+    ret = 0;
   if (0 != ret)
   {
     fprintf (stderr,
@@ -779,7 +857,7 @@ expect_basic_n (const char *hdr, size_t hdr_len,
     fprintf (stderr,
              "The check is at line: %u\n\n", line_num);
   }
-  free_AuthRqHeader ();
+  clean_AuthHeaders ();
 
   return ret;
 }
@@ -911,51 +989,38 @@ expect_digest_n (const char *hdr, size_t hdr_len,
                  int userhash,
                  unsigned int line_num)
 {
-  const struct MHD_AuthRqHeader *h;
+  const struct MHD_RqDAuth *h;
   unsigned int ret;
 
   mhd_assert (NULL != hdr);
   mhd_assert (0 != hdr_len);
 
-  h = get_AuthRqHeader (1, hdr, hdr_len);
-  mhd_assert (NULL != h);
-  if (MHD_AUTHTYPE_DIGEST != h->auth_type)
-  {
-    fprintf (stderr,
-             "'Authorization' header parsing FAILED:\n"
-             "Wrong type:\tRESULT: %s\tEXPECTED: %s\n",
-             get_auth_type_str (h->auth_type),
-             get_auth_type_str (MHD_AUTHTYPE_DIGEST));
-    ret = 1;
-  }
-  else
-  {
-    const struct MHD_RqDAuth *params;
-    if (NULL == h->params.dauth)
-      mhdErrorExitDesc ("'params.dauth' pointer is NULL");
-    params = h->params.dauth;
-    ret = 0;
+  add_AuthHeader (hdr, hdr_len);
 
-    ret += cmp_dauth_param ("nonce", &params->nonce, nonce);
-    ret += cmp_dauth_param ("algorithm", &params->algorithm, algorithm);
-    ret += cmp_dauth_param ("response", &params->response, response);
-    ret += cmp_dauth_param ("username", &params->username, username);
-    ret += cmp_dauth_param ("username_ext", &params->username_ext,
-                            username_ext);
-    ret += cmp_dauth_param ("realm", &params->realm, realm);
-    ret += cmp_dauth_param ("uri", &params->uri, uri);
-    ret += cmp_dauth_param ("qop", &params->qop, qop);
-    ret += cmp_dauth_param ("cnonce", &params->cnonce, cnonce);
-    ret += cmp_dauth_param ("nc", &params->nc, nc);
-    if (params->userhash != ! (! userhash))
-    {
-      ret += 1;
-      fprintf (stderr, "Parameter 'userhash' parsed incorrectly:\n");
-      fprintf (stderr, "\tRESULT  :\t%s\n",
-               params->userhash ? "true" : "false");
-      fprintf (stderr, "\tEXPECTED:\t%s\n",
-               userhash ? "true" : "false");
-    }
+  h = get_DAuthRqParams ();
+  if (NULL == h)
+    mhdErrorExitDesc ("'MHD_get_rq_dauth_params_()' returned NULL");
+  ret = 0;
+
+  ret += cmp_dauth_param ("nonce", &h->nonce, nonce);
+  ret += cmp_dauth_param ("algorithm", &h->algorithm, algorithm);
+  ret += cmp_dauth_param ("response", &h->response, response);
+  ret += cmp_dauth_param ("username", &h->username, username);
+  ret += cmp_dauth_param ("username_ext", &h->username_ext,
+                          username_ext);
+  ret += cmp_dauth_param ("realm", &h->realm, realm);
+  ret += cmp_dauth_param ("uri", &h->uri, uri);
+  ret += cmp_dauth_param ("qop", &h->qop, qop);
+  ret += cmp_dauth_param ("cnonce", &h->cnonce, cnonce);
+  ret += cmp_dauth_param ("nc", &h->nc, nc);
+  if (h->userhash != ! (! userhash))
+  {
+    ret += 1;
+    fprintf (stderr, "Parameter 'userhash' parsed incorrectly:\n");
+    fprintf (stderr, "\tRESULT  :\t%s\n",
+             h->userhash ? "true" : "false");
+    fprintf (stderr, "\tEXPECTED:\t%s\n",
+             userhash ? "true" : "false");
   }
   if (0 != ret)
   {
@@ -964,7 +1029,7 @@ expect_digest_n (const char *hdr, size_t hdr_len,
     fprintf (stderr,
              "The check is at line: %u\n\n", line_num);
   }
-  free_AuthRqHeader ();
+  clean_AuthHeaders ();
 
   return ret;
 }
@@ -1014,6 +1079,29 @@ check_digest (void)
   r += expect_digest ("Digest nc=\"1\\;\", ", NULL, NULL, NULL, NULL, NULL, \
                       NULL, NULL, NULL, NULL, "1\\;", 0);
 
+  r += expect_digest ("Digest userhash=false", NULL, NULL, NULL, NULL, NULL, \
+                      NULL, NULL, NULL, NULL, NULL, 0);
+  r += expect_digest ("Digest userhash=\"false\"", NULL, NULL, NULL, NULL, 
NULL, \
+                      NULL, NULL, NULL, NULL, NULL, 0);
+  r += expect_digest ("Digest userhash=foo", NULL, NULL, NULL, NULL, NULL, \
+                      NULL, NULL, NULL, NULL, NULL, 0);
+  r += expect_digest ("Digest userhash=true", NULL, NULL, NULL, NULL, NULL, \
+                      NULL, NULL, NULL, NULL, NULL, 1);
+  r += expect_digest ("Digest userhash=\"true\"", NULL, NULL, NULL, NULL, 
NULL, \
+                      NULL, NULL, NULL, NULL, NULL, 1);
+  r += expect_digest ("Digest userhash=\"\\t\\r\\u\\e\"", NULL, NULL, NULL, \
+                      NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
+  r += expect_digest ("Digest userhash=TRUE", NULL, NULL, NULL, NULL, NULL, \
+                      NULL, NULL, NULL, NULL, NULL, 1);
+  r += expect_digest ("Digest userhash=True", NULL, NULL, NULL, NULL, NULL, \
+                      NULL, NULL, NULL, NULL, NULL, 1);
+  r += expect_digest ("Digest userhash = true", NULL, NULL, NULL, NULL, \
+                      NULL,  NULL, NULL, NULL, NULL, NULL, 1);
+  r += expect_digest ("Digest userhash=True2", NULL, NULL, NULL, NULL, NULL, \
+                      NULL, NULL, NULL, NULL, NULL, 0);
+  r += expect_digest ("Digest userhash=\" true\"", NULL, NULL, NULL, NULL, \
+                      NULL,  NULL, NULL, NULL, NULL, NULL, 0);
+
   r += expect_digest ("Digest username=\"test@example.com\", " \
                       "realm=\"users@example.com\", 
nonce=\"32141232413abcde\", " \
                       "uri=\"/example\", qop=auth, nc=00000001, 
cnonce=\"0a4f113b\", " \
@@ -1209,11 +1297,114 @@ check_digest (void)
 
 #endif /* DAUTH_SUPPORT */
 
+#define TEST_AUTH_STR "dXNlcjpwYXNz"
+
+static unsigned int
+check_two_auths (void)
+{
+  unsigned int ret;
+  static struct MHD_HTTP_Req_Header h1;
+  static struct MHD_HTTP_Req_Header h2;
+  static struct MHD_HTTP_Req_Header h3;
+#ifdef BAUTH_SUPPORT
+  const struct MHD_RqBAuth *bauth;
+#endif /* BAUTH_SUPPORT */
+#ifdef DAUTH_SUPPORT
+  const struct MHD_RqDAuth *dauth;
+#endif /* DAUTH_SUPPORT */
+
+  if ((NULL != conn.rq.headers_received) ||
+      (NULL != conn.rq.headers_received_tail))
+    externalErrorExitDesc ("Connection's test headers are not empty already");
+
+  /* Init and use both Basic and Digest Auth headers */
+  memset (&h1, 0, sizeof(h1));
+  memset (&h2, 0, sizeof(h2));
+  memset (&h3, 0, sizeof(h3));
+
+  h1.kind = MHD_HEADER_KIND;
+  h1.header = MHD_HTTP_HEADER_HOST; /* Just some random header */
+  h1.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_HOST);
+  h1.value = "localhost";
+  h1.value_size = strlen (h1.value);
+
+  h2.kind = MHD_HEADER_KIND;
+  h2.header = MHD_HTTP_HEADER_AUTHORIZATION;
+  h2.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_AUTHORIZATION);
+  h2.value = "Basic " TEST_AUTH_STR;
+  h2.value_size = strlen (h2.value);
+
+  h3.kind = MHD_HEADER_KIND;
+  h3.header = MHD_HTTP_HEADER_AUTHORIZATION;
+  h3.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_AUTHORIZATION);
+  h3.value = "Digest cnonce=" TEST_AUTH_STR;
+  h3.value_size = strlen (h3.value);
+
+  conn.rq.headers_received = &h1;
+  h1.next = &h2;
+  h2.prev = &h1;
+  h2.next = &h3;
+  h3.prev = &h2;
+  conn.rq.headers_received_tail = &h3;
+
+  conn.state = MHD_CONNECTION_FULL_REQ_RECEIVED; /* Should be a typical value 
*/
+
+  ret = 0;
+#ifdef BAUTH_SUPPORT
+  bauth = get_BAuthRqParams ();
+#endif /* BAUTH_SUPPORT */
+#ifdef DAUTH_SUPPORT
+  dauth = get_DAuthRqParams ();
+#endif /* DAUTH_SUPPORT */
+#ifdef BAUTH_SUPPORT
+  if (NULL == bauth)
+  {
+    fprintf (stderr, "No Basic Authorization header detected. Line: %u\n",
+             (unsigned int) __LINE__);
+    ret++;
+  }
+  else if ((MHD_STATICSTR_LEN_ (TEST_AUTH_STR) != bauth->token68.len) ||
+           (0 != memcmp (bauth->token68.str, TEST_AUTH_STR,
+                         bauth->token68.len)))
+  {
+    fprintf (stderr, "Basic Authorization token does not match. Line: %u\n",
+             (unsigned int) __LINE__);
+    ret++;
+  }
+#endif /* BAUTH_SUPPORT */
+#ifdef DAUTH_SUPPORT
+  if (NULL == dauth)
+  {
+    fprintf (stderr, "No Digest Authorization header detected. Line: %u\n",
+             (unsigned int) __LINE__);
+    ret++;
+  }
+  else if ((MHD_STATICSTR_LEN_ (TEST_AUTH_STR) != dauth->cnonce.value.len) ||
+           (0 != memcmp (dauth->cnonce.value.str, TEST_AUTH_STR,
+                         dauth->cnonce.value.len)))
+  {
+    fprintf (stderr, "Digest Authorization 'cnonce' does not match. Line: 
%u\n",
+             (unsigned int) __LINE__);
+    ret++;
+  }
+#endif /* DAUTH_SUPPORT */
+
+  /* Cleanup */
+  conn.rq.headers_received = NULL;
+  conn.rq.headers_received_tail = NULL;
+  conn.state = MHD_CONNECTION_INIT;
+
+  return ret;
+}
+
+
 int
 main (int argc, char *argv[])
 {
   unsigned int errcount = 0;
   (void) argc; (void) argv; /* Unused. Silent compiler warning. */
+  test_global_init ();
+
   errcount += check_type ();
 #ifdef BAUTH_SUPPORT
   errcount += check_basic ();
@@ -1221,6 +1412,7 @@ main (int argc, char *argv[])
 #ifdef DAUTH_SUPPORT
   errcount += check_digest ();
 #endif /* DAUTH_SUPPORT */
+  errcount += check_two_auths ();
   if (0 == errcount)
     printf ("All tests were passed without errors.\n");
   return errcount == 0 ? 0 : 1;
diff --git a/src/microhttpd/test_postprocessor.c 
b/src/microhttpd/test_postprocessor.c
index 73607eaf..ac1e704c 100644
--- a/src/microhttpd/test_postprocessor.c
+++ b/src/microhttpd/test_postprocessor.c
@@ -239,7 +239,7 @@ test_urlencoding_case (unsigned int want_start,
 
     memset (&connection, 0, sizeof (struct MHD_Connection));
     memset (&header, 0, sizeof (struct MHD_HTTP_Res_Header));
-    connection.headers_received = &header;
+    connection.rq.headers_received = &header;
     header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
     header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
     header.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_TYPE);
@@ -389,7 +389,7 @@ test_multipart_garbage (void)
     want_off = FORM_START;
     memset (&connection, 0, sizeof (struct MHD_Connection));
     memset (&header, 0, sizeof (struct MHD_HTTP_Res_Header));
-    connection.headers_received = &header;
+    connection.rq.headers_received = &header;
     header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
     header.value =
       MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x";
@@ -451,7 +451,7 @@ test_multipart_splits (void)
     want_off = FORM_START;
     memset (&connection, 0, sizeof (struct MHD_Connection));
     memset (&header, 0, sizeof (struct MHD_HTTP_Res_Header));
-    connection.headers_received = &header;
+    connection.rq.headers_received = &header;
     header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
     header.value =
       MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x";
@@ -510,7 +510,7 @@ test_multipart (void)
 
   memset (&connection, 0, sizeof (struct MHD_Connection));
   memset (&header, 0, sizeof (struct MHD_HTTP_Res_Header));
-  connection.headers_received = &header;
+  connection.rq.headers_received = &header;
   header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
   header.value =
     MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x";
@@ -567,7 +567,7 @@ test_nested_multipart (void)
 
   memset (&connection, 0, sizeof (struct MHD_Connection));
   memset (&header, 0, sizeof (struct MHD_HTTP_Res_Header));
-  connection.headers_received = &header;
+  connection.rq.headers_received = &header;
   header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
   header.value =
     MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x";
@@ -642,7 +642,7 @@ test_overflow (void)
 
   memset (&connection, 0, sizeof (struct MHD_Connection));
   memset (&header, 0, sizeof (struct MHD_HTTP_Res_Header));
-  connection.headers_received = &header;
+  connection.rq.headers_received = &header;
   header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
   header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
   header.header_size = strlen (header.header);
@@ -701,8 +701,8 @@ test_empty_key (void)
     memset (&connection, 0, sizeof (struct MHD_Connection));
     memset (&header, 0, sizeof (struct MHD_HTTP_Res_Header));
 
-    connection.headers_received = &header;
-    connection.headers_received_tail = &header;
+    connection.rq.headers_received = &header;
+    connection.rq.headers_received_tail = &header;
     header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
     header.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_TYPE);
     header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
@@ -755,8 +755,8 @@ test_double_value (void)
     memset (&connection, 0, sizeof (struct MHD_Connection));
     memset (&header, 0, sizeof (struct MHD_HTTP_Res_Header));
 
-    connection.headers_received = &header;
-    connection.headers_received_tail = &header;
+    connection.rq.headers_received = &header;
+    connection.rq.headers_received_tail = &header;
     header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
     header.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_TYPE);
     header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
diff --git a/src/microhttpd/test_postprocessor_amp.c 
b/src/microhttpd/test_postprocessor_amp.c
index 1ae61691..ba24601f 100644
--- a/src/microhttpd/test_postprocessor_amp.c
+++ b/src/microhttpd/test_postprocessor_amp.c
@@ -81,7 +81,7 @@ main (int argc, char *const *argv)
   num_errors = 0;
   memset (&connection, 0, sizeof (struct MHD_Connection));
   memset (&header, 0, sizeof (struct MHD_HTTP_Res_Header));
-  connection.headers_received = &header;
+  connection.rq.headers_received = &header;
   header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
   header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
   header.header_size = strlen (header.header);
diff --git a/src/microhttpd/test_postprocessor_large.c 
b/src/microhttpd/test_postprocessor_large.c
index 5e500ed3..61f2887b 100644
--- a/src/microhttpd/test_postprocessor_large.c
+++ b/src/microhttpd/test_postprocessor_large.c
@@ -77,7 +77,7 @@ test_simple_large (void)
   data[sizeof (data) - 1] = '\0';
   memset (&connection, 0, sizeof (struct MHD_Connection));
   memset (&header, 0, sizeof (struct MHD_HTTP_Res_Header));
-  connection.headers_received = &header;
+  connection.rq.headers_received = &header;
   header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
   header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
   header.header_size = strlen (header.header);

-- 
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]