diff options
| author | Garrett D'Amore <garrett@damore.org> | 2019-02-17 23:02:03 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2019-02-17 23:02:03 -0800 |
| commit | b6f6ce85693959db78adf513f3f748043ef114c8 (patch) | |
| tree | e00611e931548d10d4cda5f1e8d9e17ff296dd44 /src/supplemental | |
| parent | 29c6d4e0a2f7d0627fbfaa6589b5c4e40689ca57 (diff) | |
| download | nng-b6f6ce85693959db78adf513f3f748043ef114c8.tar.gz nng-b6f6ce85693959db78adf513f3f748043ef114c8.tar.bz2 nng-b6f6ce85693959db78adf513f3f748043ef114c8.zip | |
fixes #869 nng_http_handler_set_tree fails match if path is /
Diffstat (limited to 'src/supplemental')
| -rw-r--r-- | src/supplemental/http/http_server.c | 11 |
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); } |
