aboutsummaryrefslogtreecommitdiff
path: root/tests/httpclient.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/httpclient.c')
-rw-r--r--tests/httpclient.c129
1 files changed, 60 insertions, 69 deletions
diff --git a/tests/httpclient.c b/tests/httpclient.c
index f3307fc1..b23449f1 100644
--- a/tests/httpclient.c
+++ b/tests/httpclient.c
@@ -14,8 +14,8 @@
#include <arpa/inet.h>
#endif
+#include <nng/http.h>
#include <nng/nng.h>
-#include <nng/supplemental/http/http.h>
#include "core/nng_impl.h"
@@ -26,7 +26,7 @@ TestMain("HTTP Client", {
Convey("Given a TCP connection to example.com", {
nng_aio *aio;
nng_http_client *cli;
- nng_http_conn *http;
+ nng_http *http;
nng_url *url;
So(nng_aio_alloc(&aio, NULL, NULL) == 0);
@@ -41,31 +41,24 @@ TestMain("HTTP Client", {
http = nng_aio_get_output(aio, 0);
Reset({
nng_http_client_free(cli);
- nng_http_conn_close(http);
+ nng_http_close(http);
nng_aio_free(aio);
nng_url_free(url);
});
Convey("We can initiate a message", {
- nng_http_req *req;
- nng_http_res *res;
-
So(http != NULL);
- So(nng_http_req_alloc(&req, url) == 0);
- So(nng_http_res_alloc(&res) == 0);
- Reset({
- nng_http_req_free(req);
- nng_http_res_free(res);
- });
- nng_http_conn_write_req(http, req, aio);
+ So(nng_http_set_uri(http, nng_url_path(url), NULL) ==
+ 0);
+ nng_http_write_request(http, aio);
nng_aio_wait(aio);
So(nng_aio_result(aio) == 0);
- nng_http_conn_read_res(http, res, aio);
+ nng_http_read_response(http, aio);
nng_aio_wait(aio);
So(nng_aio_result(aio) == 0);
- So(nng_http_res_get_status(res) == 200);
+ So(nng_http_get_status(http) == 200);
Convey("The message contents are correct", {
void *data;
@@ -73,8 +66,8 @@ TestMain("HTTP Client", {
size_t sz;
nng_iov iov;
- cstr = nng_http_res_get_header(
- res, "Content-Length");
+ cstr = nng_http_get_header(
+ http, "Content-Length");
So(cstr != NULL);
sz = atoi(cstr);
So(sz > 0);
@@ -90,7 +83,7 @@ TestMain("HTTP Client", {
nng_aio_wait(aio);
So(nng_aio_result(aio) == 0);
- nng_http_conn_read_all(http, aio);
+ nng_http_read_all(http, aio);
nng_aio_wait(aio);
So(nng_aio_result(aio) == 0);
});
@@ -116,35 +109,34 @@ TestMain("HTTP Client", {
});
Convey("One off exchange works", {
- nng_http_req *req;
- nng_http_res *res;
- void *data;
- size_t len;
+ nng_http *conn;
+ void *data;
+ size_t len;
- So(nng_http_req_alloc(&req, url) == 0);
- So(nng_http_res_alloc(&res) == 0);
- Reset({
- nng_http_req_free(req);
- nng_http_res_free(res);
- });
+ nng_http_client_connect(cli, aio);
+ nng_aio_wait(aio);
+ So(nng_aio_result(aio) == 0);
+ conn = nng_aio_get_output(aio, 0);
+ Reset({ nng_http_close(conn); });
- nng_http_client_transact(cli, req, res, aio);
+ So(nng_http_set_uri(conn, nng_url_path(url), NULL) ==
+ 0);
+
+ nng_http_transact(conn, aio);
nng_aio_wait(aio);
So(nng_aio_result(aio) == 0);
- So(nng_http_res_get_status(res) == 200);
- nng_http_res_get_data(res, &data, &len);
+ So(nng_http_get_status(conn) == 200);
+ nng_http_get_body(conn, &data, &len);
});
Convey("Connection reuse works", {
- nng_http_res *res;
- nng_http_req *req;
- void *data;
- size_t len;
- nng_http_conn *conn = NULL;
+ void *data;
+ size_t len;
+ nng_http *conn = NULL;
Reset({
if (conn != NULL) {
- nng_http_conn_close(conn);
+ nng_http_close(conn);
}
});
@@ -153,20 +145,22 @@ TestMain("HTTP Client", {
So(nng_aio_result(aio) == 0);
conn = nng_aio_get_output(aio, 0);
- req = nng_http_conn_req(conn);
- res = nng_http_conn_res(conn);
- So(nng_http_req_set_url(req, url) == 0);
- nng_http_conn_transact(conn, aio);
+ So(nng_http_set_uri(conn, nng_url_path(url), NULL) ==
+ 0);
+ nng_http_transact(conn, aio);
nng_aio_wait(aio);
So(nng_aio_result(aio) == 0);
- So(nng_http_res_get_status(res) == 200);
- nng_http_res_get_data(res, &data, &len);
+ So(nng_http_get_status(conn) == 200);
+ nng_http_get_body(conn, &data, &len);
- nng_http_conn_transact(conn, aio);
+ nng_http_reset(conn);
+ So(nng_http_set_uri(conn, nng_url_path(url), NULL) ==
+ 0);
+ nng_http_transact(conn, aio);
nng_aio_wait(aio);
So(nng_aio_result(aio) == 0);
- So(nng_http_res_get_status(res) == 200);
- nng_http_res_get_data(res, &data, &len);
+ So(nng_http_get_status(conn) == 200);
+ nng_http_get_body(conn, &data, &len);
});
});
@@ -178,29 +172,27 @@ TestMain("HTTP Client", {
nng_aio *aio;
nng_http_client *cli;
nng_url *url;
- nng_http_req *req;
- nng_http_res *res;
+ nng_http *conn;
So(nng_aio_alloc(&aio, NULL, NULL) == 0);
So(nng_url_parse(&url, "http://httpbin.org/delay/30") == 0);
So(nng_http_client_alloc(&cli, url) == 0);
- So(nng_http_req_alloc(&req, url) == 0);
- So(nng_http_res_alloc(&res) == 0);
-
+ nng_http_client_connect(cli, aio);
+ nng_aio_wait(aio);
+ So(nng_aio_result(aio) == 0);
+ conn = nng_aio_get_output(aio, 0);
Reset({
nng_http_client_free(cli);
nng_url_free(url);
nng_aio_free(aio);
- nng_http_req_free(req);
- nng_http_res_free(res);
});
nng_aio_set_timeout(aio, 10); // 10 msec timeout
- So(nng_http_req_set_header(req, "Cache-Control", "no-cache") ==
+ So(nng_http_set_header(conn, "Cache-Control", "no-cache") ==
0);
- nng_http_client_transact(cli, req, res, aio);
+ nng_http_transact(conn, aio);
nng_aio_wait(aio);
So(nng_aio_result(aio) == NNG_ETIMEDOUT);
});
@@ -227,23 +219,22 @@ TestMain("HTTP Client", {
});
Convey("One off exchange works", {
- nng_http_req *req;
- nng_http_res *res;
- void *data;
- size_t len;
-
- So(nng_http_req_alloc(&req, url) == 0);
- So(nng_http_res_alloc(&res) == 0);
- Reset({
- nng_http_req_free(req);
- nng_http_res_free(res);
- });
+ void *data;
+ size_t len;
+ nng_http *conn;
- nng_http_client_transact(cli, req, res, aio);
+ nng_http_client_connect(cli, aio);
+ nng_aio_wait(aio);
+ So(nng_aio_result(aio) == 0);
+ conn = nng_aio_get_output(aio, 0);
+ Reset({ nng_http_close(conn); });
+ So(nng_http_set_uri(conn, nng_url_path(url), NULL) ==
+ 0);
+ nng_http_transact(conn, aio);
nng_aio_wait(aio);
So(nng_aio_result(aio) == 0);
- So(nng_http_res_get_status(res) == 200);
- nng_http_res_get_data(res, &data, &len);
+ So(nng_http_get_status(conn) == 200);
+ nng_http_get_body(conn, (void **) &data, &len);
});
});
})