aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental/http/http_schemes.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-11-17 22:46:42 -0800
committerGarrett D'Amore <garrett@damore.org>2020-11-17 22:49:59 -0800
commitcda4885676f009e2e7f2ad5e6c52743efc8b8924 (patch)
tree62dfc33e0559cbf84efb014dd17b687247cadda8 /src/supplemental/http/http_schemes.c
parent04974cc135ca461d8fce50fa8def0ca5fe13b101 (diff)
downloadnng-cda4885676f009e2e7f2ad5e6c52743efc8b8924.tar.gz
nng-cda4885676f009e2e7f2ad5e6c52743efc8b8924.tar.bz2
nng-cda4885676f009e2e7f2ad5e6c52743efc8b8924.zip
Centralize the scheme handling for HTTP schemes.
Diffstat (limited to 'src/supplemental/http/http_schemes.c')
-rw-r--r--src/supplemental/http/http_schemes.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/supplemental/http/http_schemes.c b/src/supplemental/http/http_schemes.c
new file mode 100644
index 00000000..df8b9208
--- /dev/null
+++ b/src/supplemental/http/http_schemes.c
@@ -0,0 +1,85 @@
+//
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+//
+// This software is supplied under the terms of the MIT License, a
+// copy of which should be located in the distribution where this
+// file was obtained (LICENSE.txt). A copy of the license may also be
+// found online at https://opensource.org/licenses/MIT.
+//
+
+#include <ctype.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include "core/nng_impl.h"
+
+#include "http_api.h"
+
+static struct {
+ const char *upper;
+ const char *lower;
+} http_schemes[] = {
+ {
+ .upper = "http",
+ .lower = "tcp",
+ },
+ {
+ .upper = "ws",
+ .lower = "tcp",
+ },
+ {
+ .upper = "https",
+ .lower = "tls+tcp",
+ },
+ {
+ .upper = "wss",
+ .lower = "tls+tcp",
+ },
+ {
+ .upper = "http4",
+ .lower = "tcp4",
+ },
+ {
+ .upper = "ws4",
+ .lower = "tcp4",
+ },
+ {
+ .upper = "http6",
+ .lower = "tcp6",
+ },
+ {
+ .upper = "ws6",
+ .lower = "tcp6",
+ },
+ {
+ .upper = "https4",
+ .lower = "tls+tcp4",
+ },
+ {
+ .upper = "wss4",
+ .lower = "tls+tcp4",
+ },
+ {
+ .upper = "https6",
+ .lower = "tls+tcp6",
+ },
+ {
+ .upper = "wss6",
+ .lower = "tls+tcp6",
+ },
+ {
+ .upper = NULL,
+ .lower = NULL,
+ },
+};
+
+const char *
+nni_http_stream_scheme(const char *upper)
+{
+ for (int i = 0; http_schemes[i].upper != NULL; i++) {
+ if (strcmp(http_schemes[i].upper, upper) == 0) {
+ return (http_schemes[i].lower);
+ }
+ }
+ return (NULL);
+} \ No newline at end of file