aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental
diff options
context:
space:
mode:
Diffstat (limited to 'src/supplemental')
-rw-r--r--src/supplemental/http/http_server.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c
index cb003aff..624ba1e4 100644
--- a/src/supplemental/http/http_server.c
+++ b/src/supplemental/http/http_server.c
@@ -95,9 +95,9 @@ nni_http_handler_init(
if ((h = NNI_ALLOC_STRUCT(h)) == NULL) {
return (NNG_ENOMEM);
}
- // Default for HTTP is /.
- if ((uri == NULL) || (strlen(uri) == 0)) {
- uri = "/";
+ // Default for HTTP is /. But remap it to "" for ease of matching.
+ if ((uri == NULL) || (strlen(uri) == 0) || (strcmp(uri, "/") == 0)) {
+ uri = "";
}
if (((h->uri = nni_strdup(uri)) == NULL) ||
((h->method = nni_strdup("GET")) == NULL)) {
@@ -159,6 +159,9 @@ nni_http_handler_get_data(nni_http_handler *h)
const char *
nni_http_handler_get_uri(nni_http_handler *h)
{
+ if (strlen(h->uri) == 0) {
+ return ("/");
+ }
return (h->uri);
}
@@ -1089,7 +1092,7 @@ nni_http_server_add_handler(nni_http_server *s, nni_http_handler *h)
// Must have a legal method (and not one that is HEAD), path,
// and handler. (The reason HEAD is verboten is that we supply
// it automatically as part of GET support.)
- if (((len = strlen(h->uri)) == 0) || (h->uri[0] != '/') ||
+ if ((((len = strlen(h->uri)) > 0) && (h->uri[0] != '/')) ||
(h->cb == NULL)) {
return (NNG_EINVAL);
}