gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-exchange] branch master updated: add helper function


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated: add helper function to detect http/https on an MHD connection
Date: Sat, 05 Oct 2019 19:02:40 +0200

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

dold pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new c944a570 add helper function to detect http/https on an MHD connection
c944a570 is described below

commit c944a5703aecc36e044f3fcd17f6fed41a3e436d
Author: Florian Dold <address@hidden>
AuthorDate: Sat Oct 5 22:32:31 2019 +0530

    add helper function to detect http/https on an MHD connection
---
 src/include/taler_util.h | 13 ++++++++
 src/util/util.c          | 79 +++++++++++++++++++++++++++++++-----------------
 2 files changed, 64 insertions(+), 28 deletions(-)

diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index 310c8895..9cfcb3dc 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -155,6 +155,19 @@ char *
 TALER_urlencode (const char *s);
 
 
+/**
+ * Find out if an MHD connection is using HTTPS (either
+ * directly or via proxy).
+ *
+ * @param connection MHD connection
+ * @returns GNUNET_YES if the MHD connection is using https,
+ *          GNUNET_NO if the MHD connection is using http,
+ *          GNUNET_SYSERR if the connection type couldn't be determined
+ */
+int
+TALER_mhd_is_https (struct MHD_Connection *connection);
+
+
 /**
  * Make an absolute URL with query parameters.
  *
diff --git a/src/util/util.c b/src/util/util.c
index 027daf42..3341aa29 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -423,6 +423,53 @@ TALER_url_absolute_raw (const char *proto,
 }
 
 
+/**
+ * Find out if an MHD connection is using HTTPS (either
+ * directly or via proxy).
+ *
+ * @param connection MHD connection
+ * @returns GNUNET_YES if the MHD connection is using https,
+ *          GNUNET_NO if the MHD connection is using http,
+ *          GNUNET_SYSERR if the connection type couldn't be determined
+ */
+int
+TALER_mhd_is_https (struct MHD_Connection *connection)
+{
+  const union MHD_ConnectionInfo *ci;
+  const union MHD_DaemonInfo *di;
+  const char *forwarded_proto = MHD_lookup_connection_value (connection,
+                                                             MHD_HEADER_KIND,
+                                                             
"X-Forwarded-Proto");
+
+  if (NULL != forwarded_proto)
+  {
+    if (0 == strcmp (forwarded_proto, "https"))
+      return GNUNET_YES;
+    if (0 == strcmp (forwarded_proto, "http"))
+      return GNUNET_NO;
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  /* likely not reverse proxy, figure out if we are
+     http by asking MHD */
+  ci = MHD_get_connection_info (connection, MHD_CONNECTION_INFO_DAEMON);
+  if (NULL == ci)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  di = MHD_get_daemon_info (ci->daemon, MHD_DAEMON_INFO_FLAGS);
+  if (NULL == di)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  if (0 != (di->flags & MHD_USE_TLS))
+    return GNUNET_YES;
+  return GNUNET_NO;
+}
+
+
 /**
  * Make an absolute URL for a given MHD connection.
  *
@@ -437,42 +484,18 @@ TALER_url_absolute_mhd (struct MHD_Connection *connection,
                         ...)
 {
   /* By default we assume we're running under HTTPS */
-  const char *proto = "https";
-  const char *forwarded_proto = MHD_lookup_connection_value (connection,
-                                                             MHD_HEADER_KIND,
-                                                             
"X-Forwarded-Proto");
+  const char *proto;
   const char *host;
   const char *forwarded_host;
   const char *prefix;
   va_list args;
   char *result;
 
-
-  if (NULL != forwarded_proto)
-  {
-    proto = forwarded_proto;
-  }
+  if (GNUNET_YES == TALER_mhd_is_https (connection))
+    proto = "https";
   else
-  {
-    /* likely not reverse proxy, figure out if we are
-       http by asking MHD */
-    const union MHD_ConnectionInfo *ci;
+    proto = "http";
 
-    ci = MHD_get_connection_info (connection,
-                                  MHD_CONNECTION_INFO_DAEMON);
-    if (NULL != ci)
-    {
-      const union MHD_DaemonInfo *di;
-
-      di = MHD_get_daemon_info (ci->daemon,
-                                MHD_DAEMON_INFO_FLAGS);
-      if (NULL != di)
-      {
-        if (0 == (di->flags & MHD_USE_TLS))
-          proto = "http";
-      }
-    }
-  }
   host = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, "Host");
   forwarded_host = MHD_lookup_connection_value (connection, MHD_HEADER_KIND,
                                                 "X-Forwarded-Host");

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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