summaryrefslogtreecommitdiff
path: root/tests/httpserver.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2019-02-17 23:02:03 -0800
committerGarrett D'Amore <garrett@damore.org>2019-02-17 23:02:03 -0800
commitb6f6ce85693959db78adf513f3f748043ef114c8 (patch)
treee00611e931548d10d4cda5f1e8d9e17ff296dd44 /tests/httpserver.c
parent29c6d4e0a2f7d0627fbfaa6589b5c4e40689ca57 (diff)
downloadnng-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 'tests/httpserver.c')
-rw-r--r--tests/httpserver.c53
1 files changed, 50 insertions, 3 deletions
diff --git a/tests/httpserver.c b/tests/httpserver.c
index c7530f88..996d20b4 100644
--- a/tests/httpserver.c
+++ b/tests/httpserver.c
@@ -8,7 +8,6 @@
// found online at https://opensource.org/licenses/MIT.
//
-
#ifdef _WIN32
#define strdup _strdup
#else
@@ -22,8 +21,8 @@
#include <nng/supplemental/http/http.h>
#include <nng/supplemental/tls/tls.h>
-#include "core/nng_impl.h"
#include "convey.h"
+#include "core/nng_impl.h"
const char *doc1 = "<html><body>Someone <b>is</b> home!</body</html>";
const char *doc2 = "This is a text file.";
@@ -485,6 +484,7 @@ TestMain("HTTP Server", {
nng_url_free(curl);
});
});
+
Convey("Custom POST handler works", {
char urlstr[32];
nng_url *url;
@@ -669,4 +669,51 @@ TestMain("HTTP Server", {
nng_url_free(curl);
});
});
-})
+
+ Convey("Root tree handler works", {
+ char urlstr[32];
+ nng_url *url;
+
+ trantest_next_address(urlstr, "http://127.0.0.1:%u");
+ So(nng_url_parse(&url, urlstr) == 0);
+ So(nng_http_server_hold(&s, url) == 0);
+
+ Reset({
+ nng_http_server_release(s);
+ nng_url_free(url);
+ });
+
+ So(nng_http_handler_alloc(&h, "/", httpecho) == 0);
+ So(nng_http_handler_set_method(h, "POST") == 0);
+ So(nng_http_handler_set_tree(h) == 0);
+ So(nng_http_server_add_handler(s, h) == 0);
+ So(nng_http_server_start(s) == 0);
+
+ Convey("Echo POST works", {
+ char fullurl[256];
+ size_t size;
+ nng_http_req *req;
+ nng_http_res *res;
+ nng_url * curl;
+ char txdata[5];
+ char * rxdata;
+
+ snprintf(txdata, sizeof(txdata), "1234");
+ So(nng_http_res_alloc(&res) == 0);
+ snprintf(fullurl, sizeof(fullurl),
+ "%s/some_sub/directory", urlstr);
+ So(nng_url_parse(&curl, fullurl) == 0);
+ So(nng_http_req_alloc(&req, curl) == 0);
+ nng_http_req_set_data(req, txdata, strlen(txdata));
+ So(nng_http_req_set_method(req, "POST") == 0);
+ So(httpdo(curl, req, res, (void **) &rxdata, &size) ==
+ 0);
+ So(nng_http_res_get_status(res) == NNG_HTTP_STATUS_OK);
+ So(size == strlen(txdata));
+ So(strncmp(txdata, rxdata, size) == 0);
+ nng_http_req_free(req);
+ nng_http_res_free(res);
+ nng_url_free(curl);
+ });
+ });
+});