aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/nng_http_client_alloc.adoc1
-rw-r--r--docs/nng_http_client_connect.adoc1
-rw-r--r--docs/nng_http_client_free.adoc1
-rw-r--r--docs/nng_http_client_get_tls.adoc1
-rw-r--r--docs/nng_http_client_set_tls.adoc1
-rw-r--r--docs/nng_http_conn_close.adoc1
-rw-r--r--docs/nng_http_conn_read.adoc1
-rw-r--r--docs/nng_http_conn_read_all.adoc1
-rw-r--r--docs/nng_http_conn_read_req.adoc1
-rw-r--r--docs/nng_http_conn_read_res.adoc1
-rw-r--r--docs/nng_http_conn_write.adoc1
-rw-r--r--docs/nng_http_conn_write_all.adoc1
-rw-r--r--docs/nng_http_conn_write_req.adoc1
-rw-r--r--docs/nng_http_conn_write_res.adoc1
-rw-r--r--docs/nng_http_handler_alloc.adoc1
-rw-r--r--docs/nng_http_handler_free.adoc1
-rw-r--r--docs/nng_http_handler_get_data.adoc1
-rw-r--r--docs/nng_http_handler_set_data.adoc1
-rw-r--r--docs/nng_http_handler_set_host.adoc1
-rw-r--r--docs/nng_http_handler_set_method.adoc1
-rw-r--r--docs/nng_http_handler_set_tree.adoc1
-rw-r--r--docs/nng_http_hijack.adoc1
-rw-r--r--docs/nng_http_req_add_header.adoc1
-rw-r--r--docs/nng_http_req_alloc.adoc1
-rw-r--r--docs/nng_http_req_copy_data.adoc1
-rw-r--r--docs/nng_http_req_del_header.adoc1
-rw-r--r--docs/nng_http_req_free.adoc1
-rw-r--r--docs/nng_http_req_get_header.adoc1
-rw-r--r--docs/nng_http_req_get_method.adoc1
-rw-r--r--docs/nng_http_req_get_uri.adoc1
-rw-r--r--docs/nng_http_req_get_version.adoc1
-rw-r--r--docs/nng_http_req_set_data.adoc1
-rw-r--r--docs/nng_http_req_set_header.adoc1
-rw-r--r--docs/nng_http_req_set_method.adoc1
-rw-r--r--docs/nng_http_req_set_uri.adoc1
-rw-r--r--docs/nng_http_req_set_version.adoc1
-rw-r--r--docs/nng_http_res_add_header.adoc1
-rw-r--r--docs/nng_http_res_alloc.adoc1
-rw-r--r--docs/nng_http_res_alloc_error.adoc1
-rw-r--r--docs/nng_http_res_copy_data.adoc1
-rw-r--r--docs/nng_http_res_del_header.adoc2
-rw-r--r--docs/nng_http_res_free.adoc1
-rw-r--r--docs/nng_http_res_get_header.adoc1
-rw-r--r--docs/nng_http_res_get_reason.adoc1
-rw-r--r--docs/nng_http_res_get_status.adoc1
-rw-r--r--docs/nng_http_res_get_version.adoc1
-rw-r--r--docs/nng_http_res_set_data.adoc1
-rw-r--r--docs/nng_http_res_set_header.adoc1
-rw-r--r--docs/nng_http_res_set_reason.adoc1
-rw-r--r--docs/nng_http_res_set_status.adoc1
-rw-r--r--docs/nng_http_res_set_version.adoc1
-rw-r--r--docs/nng_http_server_add_handler.adoc1
-rw-r--r--docs/nng_http_server_del_handler.adoc1
-rw-r--r--docs/nng_http_server_get_tls.adoc1
-rw-r--r--docs/nng_http_server_hold.adoc1
-rw-r--r--docs/nng_http_server_release.adoc1
-rw-r--r--docs/nng_http_server_set_tls.adoc1
-rw-r--r--docs/nng_http_server_start.adoc1
-rw-r--r--docs/nng_http_server_stop.adoc1
-rw-r--r--src/nng.c1
-rw-r--r--src/nng.h429
-rw-r--r--src/supplemental/http/CMakeLists.txt12
-rw-r--r--src/supplemental/http/http.h636
-rw-r--r--src/supplemental/http/http_api.h283
-rw-r--r--src/supplemental/http/http_client.c2
-rw-r--r--src/supplemental/http/http_conn.c2
-rw-r--r--src/supplemental/http/http_msg.c2
-rw-r--r--src/supplemental/http/http_public.c1
-rw-r--r--src/supplemental/http/http_server.c2
-rw-r--r--src/supplemental/websocket/websocket.c2
-rw-r--r--src/transport/ws/websocket.c2
-rw-r--r--tests/httpclient.c1
-rw-r--r--tests/httpserver.c1
73 files changed, 766 insertions, 670 deletions
diff --git a/docs/nng_http_client_alloc.adoc b/docs/nng_http_client_alloc.adoc
index 32b30ce5..92cc3f8d 100644
--- a/docs/nng_http_client_alloc.adoc
+++ b/docs/nng_http_client_alloc.adoc
@@ -18,6 +18,7 @@ nng_http_client_alloc - allocate HTTP client
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_client_alloc(nng_http_client *clientp, const nng_url *url);
-----------
diff --git a/docs/nng_http_client_connect.adoc b/docs/nng_http_client_connect.adoc
index c6a4fefc..acf6bb5a 100644
--- a/docs/nng_http_client_connect.adoc
+++ b/docs/nng_http_client_connect.adoc
@@ -18,6 +18,7 @@ nng_http_client_connect - establish HTTP client connection
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_client_connect(nng_http_client *client, nng_aio *aio);
-----------
diff --git a/docs/nng_http_client_free.adoc b/docs/nng_http_client_free.adoc
index fecb5bbf..f01bbc4d 100644
--- a/docs/nng_http_client_free.adoc
+++ b/docs/nng_http_client_free.adoc
@@ -18,6 +18,7 @@ nng_http_client_free - free HTTP client
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_client_free(nng_http_client *client);
-----------
diff --git a/docs/nng_http_client_get_tls.adoc b/docs/nng_http_client_get_tls.adoc
index ecf7f5fd..1e77e88f 100644
--- a/docs/nng_http_client_get_tls.adoc
+++ b/docs/nng_http_client_get_tls.adoc
@@ -18,6 +18,7 @@ nng_http_client_get_tls - get HTTP client TLS configuration
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_client_get_tls(nng_http_client *client, nng_tls_config **cfgp);
-----------
diff --git a/docs/nng_http_client_set_tls.adoc b/docs/nng_http_client_set_tls.adoc
index 10ff825d..616000ed 100644
--- a/docs/nng_http_client_set_tls.adoc
+++ b/docs/nng_http_client_set_tls.adoc
@@ -18,6 +18,7 @@ nng_http_client_set_tls - set HTTP client TLS configuration
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_client_set_tls(nng_http_client *client, nng_tls_config *cfg);
-----------
diff --git a/docs/nng_http_conn_close.adoc b/docs/nng_http_conn_close.adoc
index 885015a6..805fa95a 100644
--- a/docs/nng_http_conn_close.adoc
+++ b/docs/nng_http_conn_close.adoc
@@ -18,6 +18,7 @@ nng_http_conn_close - close HTTP connection
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_conn_close(nng_http_conn *conn);
-----------
diff --git a/docs/nng_http_conn_read.adoc b/docs/nng_http_conn_read.adoc
index d5d85aba..3c5c40a3 100644
--- a/docs/nng_http_conn_read.adoc
+++ b/docs/nng_http_conn_read.adoc
@@ -18,6 +18,7 @@ nng_http_conn_read - read from HTTP connection
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_conn_read(nng_http_conn *conn, nng_aio *aio);
-----------
diff --git a/docs/nng_http_conn_read_all.adoc b/docs/nng_http_conn_read_all.adoc
index 6e469ae6..cc07925a 100644
--- a/docs/nng_http_conn_read_all.adoc
+++ b/docs/nng_http_conn_read_all.adoc
@@ -18,6 +18,7 @@ nng_http_conn_read_all - read all from HTTP connection
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_conn_read_all(nng_http_conn *conn, nng_aio *aio);
-----------
diff --git a/docs/nng_http_conn_read_req.adoc b/docs/nng_http_conn_read_req.adoc
index 8759a699..a7af675d 100644
--- a/docs/nng_http_conn_read_req.adoc
+++ b/docs/nng_http_conn_read_req.adoc
@@ -18,6 +18,7 @@ nng_http_conn_read_req - read HTTP request
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_conn_read_req(nng_http_conn *conn, nng_http_req *req,
nng_aio *aio);
diff --git a/docs/nng_http_conn_read_res.adoc b/docs/nng_http_conn_read_res.adoc
index 6bfa3460..cd3845e5 100644
--- a/docs/nng_http_conn_read_res.adoc
+++ b/docs/nng_http_conn_read_res.adoc
@@ -18,6 +18,7 @@ nng_http_conn_read_res - read HTTP response
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_conn_read_res(nng_http_conn *conn, nng_http_res *res,
nng_aio *aio);
diff --git a/docs/nng_http_conn_write.adoc b/docs/nng_http_conn_write.adoc
index 0f57c0c2..926c41a6 100644
--- a/docs/nng_http_conn_write.adoc
+++ b/docs/nng_http_conn_write.adoc
@@ -18,6 +18,7 @@ nng_http_conn_write - write to HTTP connection
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_conn_write(nng_http_conn *conn, nng_aio *aio);
-----------
diff --git a/docs/nng_http_conn_write_all.adoc b/docs/nng_http_conn_write_all.adoc
index 1b5a06c3..14bad81e 100644
--- a/docs/nng_http_conn_write_all.adoc
+++ b/docs/nng_http_conn_write_all.adoc
@@ -18,6 +18,7 @@ nng_http_conn_write_all - write all to HTTP connection
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_conn_write_all(nng_http_conn *conn, nng_aio *aio);
-----------
diff --git a/docs/nng_http_conn_write_req.adoc b/docs/nng_http_conn_write_req.adoc
index d73252f9..9162aebe 100644
--- a/docs/nng_http_conn_write_req.adoc
+++ b/docs/nng_http_conn_write_req.adoc
@@ -18,6 +18,7 @@ nng_http_conn_write_req - write HTTP request
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_conn_write_req(nng_http_conn *conn, nng_http_req *req,
nng_aio *aio);
diff --git a/docs/nng_http_conn_write_res.adoc b/docs/nng_http_conn_write_res.adoc
index 31e438b4..b5601841 100644
--- a/docs/nng_http_conn_write_res.adoc
+++ b/docs/nng_http_conn_write_res.adoc
@@ -18,6 +18,7 @@ nng_http_conn_write_res - write HTTP response
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_conn_write_res(nng_http_conn *conn, nng_http_res *res,
nng_aio *aio);
diff --git a/docs/nng_http_handler_alloc.adoc b/docs/nng_http_handler_alloc.adoc
index 45ba7aff..622bea03 100644
--- a/docs/nng_http_handler_alloc.adoc
+++ b/docs/nng_http_handler_alloc.adoc
@@ -18,6 +18,7 @@ nng_http_handler_alloc - allocate HTTP server handler
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
typedef struct nng_http_handler nng_http_handler;
diff --git a/docs/nng_http_handler_free.adoc b/docs/nng_http_handler_free.adoc
index e86f34f3..a8b64cdf 100644
--- a/docs/nng_http_handler_free.adoc
+++ b/docs/nng_http_handler_free.adoc
@@ -18,6 +18,7 @@ nng_http_handler_free - free HTTP server handler
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_handler_free(nng_http_handler *h);
-----------
diff --git a/docs/nng_http_handler_get_data.adoc b/docs/nng_http_handler_get_data.adoc
index 76437f64..427430f2 100644
--- a/docs/nng_http_handler_get_data.adoc
+++ b/docs/nng_http_handler_get_data.adoc
@@ -18,6 +18,7 @@ nng_http_handler_get_data - return extra data for HTTP handler
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_handler_get_data(nng_http_handler *handler, void *data,
void (*dtor)(void *));
diff --git a/docs/nng_http_handler_set_data.adoc b/docs/nng_http_handler_set_data.adoc
index 6daac924..f9728b63 100644
--- a/docs/nng_http_handler_set_data.adoc
+++ b/docs/nng_http_handler_set_data.adoc
@@ -18,6 +18,7 @@ nng_http_handler_get_data - set extra data for HTTP handler
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void *nng_http_handler_get_data(nng_http_handler *handler, void *data,
void (*dtor)(void *));
diff --git a/docs/nng_http_handler_set_host.adoc b/docs/nng_http_handler_set_host.adoc
index 470cbead..fa3d4ecd 100644
--- a/docs/nng_http_handler_set_host.adoc
+++ b/docs/nng_http_handler_set_host.adoc
@@ -18,6 +18,7 @@ nng_http_handler_set_host - set host for HTTP handler
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_handler_set_host(nng_http_handler *handler, const char *host);
-----------
diff --git a/docs/nng_http_handler_set_method.adoc b/docs/nng_http_handler_set_method.adoc
index a993868e..c3d8fbeb 100644
--- a/docs/nng_http_handler_set_method.adoc
+++ b/docs/nng_http_handler_set_method.adoc
@@ -18,6 +18,7 @@ nng_http_handler_set_method - set HTTP handler method
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_handler_set_method(nng_http_handler *handler, const char *method);
-----------
diff --git a/docs/nng_http_handler_set_tree.adoc b/docs/nng_http_handler_set_tree.adoc
index 45b998bc..f4b2dceb 100644
--- a/docs/nng_http_handler_set_tree.adoc
+++ b/docs/nng_http_handler_set_tree.adoc
@@ -18,6 +18,7 @@ nng_http_handler_set_tree - set HTTP handler to match trees
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_handler_set_tree(nng_http_handler *handler);
-----------
diff --git a/docs/nng_http_hijack.adoc b/docs/nng_http_hijack.adoc
index 39105c1d..1cac1316 100644
--- a/docs/nng_http_hijack.adoc
+++ b/docs/nng_http_hijack.adoc
@@ -18,6 +18,7 @@ nng_http_hijack - hijack HTTP server connection
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_hijack(nng_http_conn *conn);
-----------
diff --git a/docs/nng_http_req_add_header.adoc b/docs/nng_http_req_add_header.adoc
index f929f676..84b12cf3 100644
--- a/docs/nng_http_req_add_header.adoc
+++ b/docs/nng_http_req_add_header.adoc
@@ -18,6 +18,7 @@ nng_http_req_add_header - add HTTP request header
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_req_add_header(nng_http_req *req, const char *key,
const char *val);
diff --git a/docs/nng_http_req_alloc.adoc b/docs/nng_http_req_alloc.adoc
index 32e756be..002b499b 100644
--- a/docs/nng_http_req_alloc.adoc
+++ b/docs/nng_http_req_alloc.adoc
@@ -18,6 +18,7 @@ nng_http_req_alloc - allocate HTTP request structure
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_req_alloc(nng_http_req **reqp, const nng_url *url);
-----------
diff --git a/docs/nng_http_req_copy_data.adoc b/docs/nng_http_req_copy_data.adoc
index 5410d486..c1169acb 100644
--- a/docs/nng_http_req_copy_data.adoc
+++ b/docs/nng_http_req_copy_data.adoc
@@ -18,6 +18,7 @@ nng_http_req_copy_data - copy HTTP request body
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_req_copy_data(nng_http_req *req, const void *body, size_t size);
-----------
diff --git a/docs/nng_http_req_del_header.adoc b/docs/nng_http_req_del_header.adoc
index 2ad39f47..4aa4dd58 100644
--- a/docs/nng_http_req_del_header.adoc
+++ b/docs/nng_http_req_del_header.adoc
@@ -18,6 +18,7 @@ nng_http_req_set_header - set HTTP request header
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_req_set_header(nng_http_req *req, const char *key);
diff --git a/docs/nng_http_req_free.adoc b/docs/nng_http_req_free.adoc
index 711b146b..0449b7fd 100644
--- a/docs/nng_http_req_free.adoc
+++ b/docs/nng_http_req_free.adoc
@@ -18,6 +18,7 @@ nng_http_req_free - free HTTP request structure
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_req_free(nng_http_req *req);
-----------
diff --git a/docs/nng_http_req_get_header.adoc b/docs/nng_http_req_get_header.adoc
index 5faabf1a..cae37e9f 100644
--- a/docs/nng_http_req_get_header.adoc
+++ b/docs/nng_http_req_get_header.adoc
@@ -18,6 +18,7 @@ nng_http_req_get_header - return HTTP request header
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
const char *nng_http_req_get_header(nng_http_req *req, const char *key);
-----------
diff --git a/docs/nng_http_req_get_method.adoc b/docs/nng_http_req_get_method.adoc
index 63d9970f..6dd387ad 100644
--- a/docs/nng_http_req_get_method.adoc
+++ b/docs/nng_http_req_get_method.adoc
@@ -18,6 +18,7 @@ nng_http_req_get_method - return HTTP request method
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
const char *nng_http_req_get_method(nng_http_req *req);
-----------
diff --git a/docs/nng_http_req_get_uri.adoc b/docs/nng_http_req_get_uri.adoc
index dafdb722..fad3c5fa 100644
--- a/docs/nng_http_req_get_uri.adoc
+++ b/docs/nng_http_req_get_uri.adoc
@@ -18,6 +18,7 @@ nng_http_req_get_uri - return HTTP request URI
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
const char *nng_http_req_get_method(nng_http_req *req);
-----------
diff --git a/docs/nng_http_req_get_version.adoc b/docs/nng_http_req_get_version.adoc
index 584b494c..7a2b9d32 100644
--- a/docs/nng_http_req_get_version.adoc
+++ b/docs/nng_http_req_get_version.adoc
@@ -18,6 +18,7 @@ nng_http_req_get_version - return HTTP request protocol version
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
const char *nng_http_req_get_version(nng_http_req *req);
-----------
diff --git a/docs/nng_http_req_set_data.adoc b/docs/nng_http_req_set_data.adoc
index 3d208544..dbf33106 100644
--- a/docs/nng_http_req_set_data.adoc
+++ b/docs/nng_http_req_set_data.adoc
@@ -18,6 +18,7 @@ nng_http_req_set_data - set HTTP request body
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_req_set_data(nng_http_req *req, const void *body, size_t size);
-----------
diff --git a/docs/nng_http_req_set_header.adoc b/docs/nng_http_req_set_header.adoc
index 68eb1f4a..91727dba 100644
--- a/docs/nng_http_req_set_header.adoc
+++ b/docs/nng_http_req_set_header.adoc
@@ -18,6 +18,7 @@ nng_http_req_set_header - set HTTP request header
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_req_set_header(nng_http_req *req, const char *key,
const char *val);
diff --git a/docs/nng_http_req_set_method.adoc b/docs/nng_http_req_set_method.adoc
index 1584e79b..1251b7f2 100644
--- a/docs/nng_http_req_set_method.adoc
+++ b/docs/nng_http_req_set_method.adoc
@@ -18,6 +18,7 @@ nng_http_req_set_method - set HTTP request method
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_req_set_method(nng_http_req *req, const char *method);
-----------
diff --git a/docs/nng_http_req_set_uri.adoc b/docs/nng_http_req_set_uri.adoc
index 3c7ec97f..1f034676 100644
--- a/docs/nng_http_req_set_uri.adoc
+++ b/docs/nng_http_req_set_uri.adoc
@@ -18,6 +18,7 @@ nng_http_req_set_uri - set HTTP request URI
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_req_set_uri(nng_http_req *req, const char *uri);
-----------
diff --git a/docs/nng_http_req_set_version.adoc b/docs/nng_http_req_set_version.adoc
index 1811ec57..8b716171 100644
--- a/docs/nng_http_req_set_version.adoc
+++ b/docs/nng_http_req_set_version.adoc
@@ -18,6 +18,7 @@ nng_http_req_set_version - set HTTP request protocol version
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_req_set_version(nng_http_req *req, const char *version);
-----------
diff --git a/docs/nng_http_res_add_header.adoc b/docs/nng_http_res_add_header.adoc
index 6b2dc58b..3c9c6379 100644
--- a/docs/nng_http_res_add_header.adoc
+++ b/docs/nng_http_res_add_header.adoc
@@ -18,6 +18,7 @@ nng_http_res_add_header - add HTTP response header
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_res_add_header(nng_http_res *res, const char *key,
const char *val);
diff --git a/docs/nng_http_res_alloc.adoc b/docs/nng_http_res_alloc.adoc
index 3c611257..b5e5f2ab 100644
--- a/docs/nng_http_res_alloc.adoc
+++ b/docs/nng_http_res_alloc.adoc
@@ -18,6 +18,7 @@ nng_http_res_alloc - allocate HTTP response structure
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_res_alloc(nng_http_res **resp);
-----------
diff --git a/docs/nng_http_res_alloc_error.adoc b/docs/nng_http_res_alloc_error.adoc
index 1a2dd7b9..3d86c1ee 100644
--- a/docs/nng_http_res_alloc_error.adoc
+++ b/docs/nng_http_res_alloc_error.adoc
@@ -18,6 +18,7 @@ nng_http_res_alloc_error - allocate HTTP error response
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_res_alloc_error(nng_http_res **resp, uint16_t status);
-----------
diff --git a/docs/nng_http_res_copy_data.adoc b/docs/nng_http_res_copy_data.adoc
index 38c8a842..5a05179a 100644
--- a/docs/nng_http_res_copy_data.adoc
+++ b/docs/nng_http_res_copy_data.adoc
@@ -18,6 +18,7 @@ nng_http_res_copy_data - copy HTTP response body
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_res_copy_data(nng_http_res *res, const void *body, size_t size);
-----------
diff --git a/docs/nng_http_res_del_header.adoc b/docs/nng_http_res_del_header.adoc
index 8b3c7739..836f6ff8 100644
--- a/docs/nng_http_res_del_header.adoc
+++ b/docs/nng_http_res_del_header.adoc
@@ -18,9 +18,9 @@ nng_http_res_set_header - set HTTP response header
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_res_set_header(nng_http_res *res, const char *key);
-
-----------
== DESCRIPTION
diff --git a/docs/nng_http_res_free.adoc b/docs/nng_http_res_free.adoc
index a100db32..3e21c8ec 100644
--- a/docs/nng_http_res_free.adoc
+++ b/docs/nng_http_res_free.adoc
@@ -18,6 +18,7 @@ nng_http_res_free - free HTTP response structure
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_res_free(nng_http_res *req);
-----------
diff --git a/docs/nng_http_res_get_header.adoc b/docs/nng_http_res_get_header.adoc
index 6c366d2a..6ab6da02 100644
--- a/docs/nng_http_res_get_header.adoc
+++ b/docs/nng_http_res_get_header.adoc
@@ -18,6 +18,7 @@ nng_http_res_get_header - return HTTP response header
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
const char *nng_http_res_get_header(nng_http_res *res, const char *key);
-----------
diff --git a/docs/nng_http_res_get_reason.adoc b/docs/nng_http_res_get_reason.adoc
index c296d70d..a1fbaf88 100644
--- a/docs/nng_http_res_get_reason.adoc
+++ b/docs/nng_http_res_get_reason.adoc
@@ -18,6 +18,7 @@ nng_http_res_get_reason - return HTTP response reason
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
const char *nng_http_res_get_reason(nng_http_res *res);
-----------
diff --git a/docs/nng_http_res_get_status.adoc b/docs/nng_http_res_get_status.adoc
index 74aa6f7d..1076d03f 100644
--- a/docs/nng_http_res_get_status.adoc
+++ b/docs/nng_http_res_get_status.adoc
@@ -18,6 +18,7 @@ nng_http_res_get_status - return HTTP status code
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
uint16_t nng_http_res_get_status(nng_http_res *res);
-----------
diff --git a/docs/nng_http_res_get_version.adoc b/docs/nng_http_res_get_version.adoc
index fd8026d6..922b99b9 100644
--- a/docs/nng_http_res_get_version.adoc
+++ b/docs/nng_http_res_get_version.adoc
@@ -18,6 +18,7 @@ nng_http_res_get_version - return HTTP response protocol version
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
const char *nng_http_res_get_version(nng_http_res *res);
-----------
diff --git a/docs/nng_http_res_set_data.adoc b/docs/nng_http_res_set_data.adoc
index e48d4a2f..aa66be8e 100644
--- a/docs/nng_http_res_set_data.adoc
+++ b/docs/nng_http_res_set_data.adoc
@@ -18,6 +18,7 @@ nng_http_res_set_data - set HTTP response body
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_res_set_data(nng_http_res *res, const void *body, size_t size);
-----------
diff --git a/docs/nng_http_res_set_header.adoc b/docs/nng_http_res_set_header.adoc
index 7c5f33cd..6c57bb68 100644
--- a/docs/nng_http_res_set_header.adoc
+++ b/docs/nng_http_res_set_header.adoc
@@ -18,6 +18,7 @@ nng_http_res_set_header - set HTTP response header
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_res_set_header(nng_http_res *res, const char *key,
const char *val);
diff --git a/docs/nng_http_res_set_reason.adoc b/docs/nng_http_res_set_reason.adoc
index 73b32f6c..70acc733 100644
--- a/docs/nng_http_res_set_reason.adoc
+++ b/docs/nng_http_res_set_reason.adoc
@@ -18,6 +18,7 @@ nng_http_res_set_reason - set HTTP response reason
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_res_set_reason(nng_http_res *res, const char *reason);
-----------
diff --git a/docs/nng_http_res_set_status.adoc b/docs/nng_http_res_set_status.adoc
index 21832c23..bc56e63d 100644
--- a/docs/nng_http_res_set_status.adoc
+++ b/docs/nng_http_res_set_status.adoc
@@ -18,6 +18,7 @@ nng_http_res_set_status - set HTTP response status
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_res_set_status(nng_http_res *res, uint16_t status);
-----------
diff --git a/docs/nng_http_res_set_version.adoc b/docs/nng_http_res_set_version.adoc
index 682089e5..46755caa 100644
--- a/docs/nng_http_res_set_version.adoc
+++ b/docs/nng_http_res_set_version.adoc
@@ -18,6 +18,7 @@ nng_http_res_set_version - set HTTP response protocol version
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_res_set_version(nng_http_res *res, const char *version);
-----------
diff --git a/docs/nng_http_server_add_handler.adoc b/docs/nng_http_server_add_handler.adoc
index 64645fbf..728352a5 100644
--- a/docs/nng_http_server_add_handler.adoc
+++ b/docs/nng_http_server_add_handler.adoc
@@ -18,6 +18,7 @@ nng_http_server_add_handler - add HTTP server handler
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_server_add_handler(nng_http_server *s, nng_http_handler *h);
-----------
diff --git a/docs/nng_http_server_del_handler.adoc b/docs/nng_http_server_del_handler.adoc
index e3b628e8..732671b2 100644
--- a/docs/nng_http_server_del_handler.adoc
+++ b/docs/nng_http_server_del_handler.adoc
@@ -18,6 +18,7 @@ nng_http_server_del_handler - delete HTTP server handler
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_server_del_hanlder(nng_http_server *s, nng_http_handler *h);
-----------
diff --git a/docs/nng_http_server_get_tls.adoc b/docs/nng_http_server_get_tls.adoc
index 4bd41207..0ad08f11 100644
--- a/docs/nng_http_server_get_tls.adoc
+++ b/docs/nng_http_server_get_tls.adoc
@@ -18,6 +18,7 @@ nng_http_server_get_tls - get HTTP server TLS configuration
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_server_get_tls(nng_http_server *s, nng_tls_config **cfgp);
-----------
diff --git a/docs/nng_http_server_hold.adoc b/docs/nng_http_server_hold.adoc
index 17e6397f..9abe636c 100644
--- a/docs/nng_http_server_hold.adoc
+++ b/docs/nng_http_server_hold.adoc
@@ -18,6 +18,7 @@ nng_http_server_hold - get and hold HTTP server instance
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_server_hold(nng_http_server **serverp, const nng_url *url);
-----------
diff --git a/docs/nng_http_server_release.adoc b/docs/nng_http_server_release.adoc
index 7e293981..e3d90665 100644
--- a/docs/nng_http_server_release.adoc
+++ b/docs/nng_http_server_release.adoc
@@ -18,6 +18,7 @@ nng_http_server_release - release HTTP server instance
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_server_release(nng_http_server *server);
-----------
diff --git a/docs/nng_http_server_set_tls.adoc b/docs/nng_http_server_set_tls.adoc
index 4a2949dc..0b0af128 100644
--- a/docs/nng_http_server_set_tls.adoc
+++ b/docs/nng_http_server_set_tls.adoc
@@ -18,6 +18,7 @@ nng_http_server_set_tls - set HTTP server TLS configuration
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_server_set_tls(nng_http_server *s, nng_tls_config *cfg);
-----------
diff --git a/docs/nng_http_server_start.adoc b/docs/nng_http_server_start.adoc
index 7de4cb40..13561d9d 100644
--- a/docs/nng_http_server_start.adoc
+++ b/docs/nng_http_server_start.adoc
@@ -18,6 +18,7 @@ nng_http_server_start - start HTTP server
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
int nng_http_server_start(nng_http_server *server);
-----------
diff --git a/docs/nng_http_server_stop.adoc b/docs/nng_http_server_stop.adoc
index f2577b2e..32655d9a 100644
--- a/docs/nng_http_server_stop.adoc
+++ b/docs/nng_http_server_stop.adoc
@@ -18,6 +18,7 @@ nng_http_server_stop - stop HTTP server
[source, c]
-----------
#include <nng/nng.h>
+#include <nng/supplemental/http/http.h>
void nng_http_server_stop(nng_http_server *server);
-----------
diff --git a/src/nng.c b/src/nng.c
index ce296782..b906431b 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -9,7 +9,6 @@
//
#include "core/nng_impl.h"
-#include "supplemental/http/http.h"
// This file provides the "public" API. This is a thin wrapper around
// internal API functions. We use the public prefix instead of internal,
diff --git a/src/nng.h b/src/nng.h
index 1d590b70..779612c7 100644
--- a/src/nng.h
+++ b/src/nng.h
@@ -768,435 +768,6 @@ NNG_DECL void nng_url_free(nng_url *);
// nng_url_clone clones a URL structure.
NNG_DECL int nng_url_clone(nng_url **, const nng_url *);
-// HTTP API. Only present if HTTP support compiled into the library.
-// Functions will return NNG_ENOTSUP (or NULL or 0 as appropriate)
-// if the library lacks support for HTTP.
-
-// HTTP status codes. This list is not exhaustive.
-enum nng_http_status {
- NNG_HTTP_STATUS_CONTINUE = 100,
- NNG_HTTP_STATUS_SWITCHING = 101,
- NNG_HTTP_STATUS_PROCESSING = 102,
- NNG_HTTP_STATUS_OK = 200,
- NNG_HTTP_STATUS_CREATED = 201,
- NNG_HTTP_STATUS_ACCEPTED = 202,
- NNG_HTTP_STATUS_NOT_AUTHORITATIVE = 203,
- NNG_HTTP_STATUS_NO_CONTENT = 204,
- NNG_HTTP_STATUS_RESET_CONTENT = 205,
- NNG_HTTP_STATUS_PARTIAL_CONTENT = 206,
- NNG_HTTP_STATUS_MULTI_STATUS = 207,
- NNG_HTTP_STATUS_ALREADY_REPORTED = 208,
- NNG_HTTP_STATUS_IM_USED = 226,
- NNG_HTTP_STATUS_MULTIPLE_CHOICES = 300,
- NNG_HTTP_STATUS_STATUS_MOVED_PERMANENTLY = 301,
- NNG_HTTP_STATUS_FOUND = 302,
- NNG_HTTP_STATUS_SEE_OTHER = 303,
- NNG_HTTP_STATUS_NOT_MODIFIED = 304,
- NNG_HTTP_STATUS_USE_PROXY = 305,
- NNG_HTTP_STATUS_TEMPORARY_REDIRECT = 307,
- NNG_HTTP_STATUS_PERMANENT_REDIRECT = 308,
- NNG_HTTP_STATUS_BAD_REQUEST = 400,
- NNG_HTTP_STATUS_UNAUTHORIZED = 401,
- NNG_HTTP_STATUS_PAYMENT_REQUIRED = 402,
- NNG_HTTP_STATUS_FORBIDDEN = 403,
- NNG_HTTP_STATUS_NOT_FOUND = 404,
- NNG_HTTP_STATUS_METHOD_NOT_ALLOWED = 405,
- NNG_HTTP_STATUS_NOT_ACCEPTABLE = 406,
- NNG_HTTP_STATUS_PROXY_AUTH_REQUIRED = 407,
- NNG_HTTP_STATUS_REQUEST_TIMEOUT = 408,
- NNG_HTTP_STATUS_CONFLICT = 409,
- NNG_HTTP_STATUS_GONE = 410,
- NNG_HTTP_STATUS_LENGTH_REQUIRED = 411,
- NNG_HTTP_STATUS_PRECONDITION_FAILED = 412,
- NNG_HTTP_STATUS_PAYLOAD_TOO_LARGE = 413,
- NNG_HTTP_STATUS_ENTITY_TOO_LONG = 414,
- NNG_HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE = 415,
- NNG_HTTP_STATUS_RANGE_NOT_SATISFIABLE = 416,
- NNG_HTTP_STATUS_EXPECTATION_FAILED = 417,
- NNG_HTTP_STATUS_TEAPOT = 418,
- NNG_HTTP_STATUS_UNPROCESSABLE_ENTITY = 422,
- NNG_HTTP_STATUS_LOCKED = 423,
- NNG_HTTP_STATUS_FAILED_DEPENDENCY = 424,
- NNG_HTTP_STATUS_UPGRADE_REQUIRED = 426,
- NNG_HTTP_STATUS_PRECONDITION_REQUIRED = 428,
- NNG_HTTP_STATUS_TOO_MANY_REQUESTS = 429,
- NNG_HTTP_STATUS_HEADERS_TOO_LARGE = 431,
- NNG_HTTP_STATUS_UNAVAIL_LEGAL_REASONS = 451,
- NNG_HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
- NNG_HTTP_STATUS_NOT_IMPLEMENTED = 501,
- NNG_HTTP_STATUS_BAD_GATEWAY = 502,
- NNG_HTTP_STATUS_SERVICE_UNAVAILABLE = 503,
- NNG_HTTP_STATUS_GATEWAY_TIMEOUT = 504,
- NNG_HTTP_STATUS_HTTP_VERSION_NOT_SUPP = 505,
- NNG_HTTP_STATUS_VARIANT_ALSO_NEGOTIATES = 506,
- NNG_HTTP_STATUS_INSUFFICIENT_STORAGE = 507,
- NNG_HTTP_STATUS_LOOP_DETECTED = 508,
- NNG_HTTP_STATUS_NOT_EXTENDED = 510,
- NNG_HTTP_STATUS_NETWORK_AUTH_REQUIRED = 511,
-};
-
-// nng_http_req represents an HTTP request.
-typedef struct nng_http_req nng_http_req;
-
-// nng_http_req_alloc creates a vanilla HTTP request object. The object is
-// initialized with the given URL object for an HTTP/1.1 GET request by
-// default. It also adds the Host: header required for HTTP/1.1. If the
-// url is NULL, then the uri and Host: header are uninitialized, and will
-// need to be set explicitly.
-NNG_DECL int nng_http_req_alloc(nng_http_req **, const nng_url *);
-
-// nng_http_req_free frees an HTTP request object.
-NNG_DECL void nng_http_req_free(nng_http_req *);
-
-// nng_http_req_get_method returns the method.
-NNG_DECL const char *nng_http_req_get_method(nng_http_req *);
-
-// nng_http_req_get_version returns the version, usually HTTP/1.1.
-NNG_DECL const char *nng_http_req_get_version(nng_http_req *);
-
-// nng_http_req_get_uri returns the "abs-uri", which is URL without
-// the scheme, host, or port.
-NNG_DECL const char *nng_http_req_get_uri(nng_http_req *);
-
-// nng_http_req_set_header sets an HTTP header, replacing any previous value
-// that might have been present.
-NNG_DECL int nng_http_req_set_header(
- nng_http_req *, const char *, const char *);
-
-// nng_http_req_add_header adds an HTTP header, without disrupting any other
-// with the same name that might have been present.
-NNG_DECL int nng_http_req_add_header(
- nng_http_req *, const char *, const char *);
-
-// nng_http_req_del_header deletes all occurrences of a named header.
-NNG_DECL int nng_http_req_del_header(nng_http_req *, const char *);
-
-// nng_http_req_get_header looks up a header with the named, returns NULL
-// if not found.
-NNG_DECL const char *nng_http_req_get_header(nng_http_req *, const char *);
-
-// nng_http_req_set_method is used to change the method of a request.
-// The method should be an upper case HTTP method, like POST, or DELETE.
-// Null sets the default ("GET").
-NNG_DECL int nng_http_req_set_method(nng_http_req *, const char *);
-
-// nng_http_req_set_version is used to change the version of a request.
-// Normally the version is "HTTP/1.1". Note that the framework does
-// not support HTTP/2 at all. Null sets the default ("HTTP/1.1").
-NNG_DECL int nng_http_req_set_version(nng_http_req *, const char *);
-
-// nng_http_req_set_uri is used to change the URI of a request. This
-// should be an "abs-uri", that is a path, plus query and fragment if
-// needed. The scheme, host, and port don't belong here. The URI should
-// start with a leading '/' per HTTP.
-NNG_DECL int nng_http_req_set_uri(nng_http_req *, const char *);
-
-// nng_http_req_set_data adds entity data to the request. The
-// data object must persist (so only really useful for static data).
-// The content-length header is updated as well, but the caller should
-// probably set the content-type header.
-NNG_DECL int nng_http_req_set_data(nng_http_req *, const void *, size_t);
-
-// nng_http_req_copy_data adds entity data to the response. A private
-// copy of the data is made (will be freed with the request).
-// The content-length header is updated as well, but the caller should
-// probably set the content-type header.
-NNG_DECL int nng_http_req_copy_data(nng_http_req *, const void *, size_t);
-
-// nng_http_res represents an HTTP response.
-typedef struct nng_http_res nng_http_res;
-
-// nng_http_res_alloc creates a vanilla HTTP response object. The object is
-// initialized for an HTTP/1.1 200 OK response by default.
-NNG_DECL int nng_http_res_alloc(nng_http_res **);
-
-// nng_http_res_alloc_error creates an error HTTP response object. The object
-// is initialized for an HTTP/1.1 response, and contains an associated
-// generic HTML error page.
-NNG_DECL int nng_http_res_alloc_error(nng_http_res **, uint16_t);
-
-// nng_http_res_free frees an HTTP response object.
-NNG_DECL void nng_http_res_free(nng_http_res *);
-
-// nng_http_res_get_status returns the HTTP status code from the server.
-NNG_DECL uint16_t nng_http_res_get_status(nng_http_res *);
-
-// nng_http_res_set_status sets the HTTP status code.
-NNG_DECL int nng_http_res_set_status(nng_http_res *, uint16_t);
-
-// nng_http_res_get_reason returns the human readable status message
-// that the server responds (or responded) with.
-NNG_DECL const char *nng_http_res_get_reason(nng_http_res *);
-
-// nng_http_res_set_rason sets the human readable status message.
-// NULL means that a default reason is used based on the status code.
-NNG_DECL int nng_http_res_set_reason(nng_http_res *, const char *);
-
-// nng_http_res_set_header sets an HTTP header, replacing any previous value
-// that might have been present.
-NNG_DECL int nng_http_res_set_header(
- nng_http_res *, const char *, const char *);
-
-// nng_http_res_add_header adds an HTTP header, without disrupting any other
-// with the same name that might have been present.
-NNG_DECL int nng_http_res_add_header(
- nng_http_res *, const char *, const char *);
-
-// nng_http_res_del_header deletes all occurrences of a named header.
-NNG_DECL int nng_http_res_del_header(nng_http_res *, const char *);
-
-// nng_http_res_get_header looks up a header with the named, returns NULL
-// if not found.
-NNG_DECL const char *nng_http_res_get_header(nng_http_res *, const char *);
-
-// nng_http_res_set_version is used to change the version of a response.
-// Normally the version is "HTTP/1.1". Note that the framework does
-// not support HTTP/2 at all. NULL sets the default ("HTTP/1.1").
-NNG_DECL int nng_http_res_set_version(nng_http_res *, const char *);
-
-// nng_http_res_get_version returns the version, usually HTTP/1.1.
-NNG_DECL const char *nng_http_res_get_version(nng_http_res *);
-
-// nng_http_res_set_data adds entity data to the response. The
-// data object must persist (so only really useful for static data).
-// The content-length header is updated as well, but the caller should
-// probably set the content-type header.
-NNG_DECL int nng_http_res_set_data(nng_http_res *, const void *, size_t);
-
-// nng_http_res_copy_data adds entity data to the response. A private
-// copy of the data is made (will be freed with the request).
-// The content-length header is updated as well, but the caller should
-// probably set the content-type header.
-NNG_DECL int nng_http_res_copy_data(nng_http_res *, const void *, size_t);
-
-// An nng_http_conn represents an underlying "connection". It may be
-// a TCP channel, or a TLS channel, but the main thing is that this is
-// normally only used for exchanging HTTP requests and responses.
-typedef struct nng_http_conn nng_http_conn;
-
-// nng_http_conn_close closes the underlying channel. Applications should
-// not use this channel after this operation is performed.
-NNG_DECL void nng_http_conn_close(nng_http_conn *);
-
-// nng_http_conn_read attempts to read data from the connection. This
-// completes as soon as at least one byte is read; it does not wait
-// for the entire aio to be filled.
-NNG_DECL void nng_http_conn_read(nng_http_conn *, nng_aio *);
-
-// nng_http_conn_read_all is like nng_http_conn_read, but it does not
-// finish until either all the requested data is read, or an error occurs.
-NNG_DECL void nng_http_conn_read_all(nng_http_conn *, nng_aio *);
-
-// nng_http_conn_write attempts to write data, but it can write less
-// than the amount requested. (It completes as soon as at least one
-// byte is written.)
-NNG_DECL void nng_http_conn_write(nng_http_conn *, nng_aio *);
-
-// nng_http_conn_write_all is like nng_http_conn_write, but it does not
-// finish until either all the requested data is written, or an error occurs.
-NNG_DECL void nng_http_conn_write_all(nng_http_conn *, nng_aio *);
-
-// nng_http_conn_write_req writes the entire request. It will also write any
-// data that has been attached.
-NNG_DECL void nng_http_conn_write_req(
- nng_http_conn *, nng_http_req *, nng_aio *);
-
-// nng_http_conn_write_res writes the entire response. It will also write any
-// data that has been attached.
-NNG_DECL void nng_http_conn_write_res(
- nng_http_conn *, nng_http_res *, nng_aio *);
-
-// nng_http_conn_read_req reads an entire request, EXCEPT for any entity
-// data. The caller is responsible for processing the headers in the request
-// and reading any submitted entity data itself.
-NNG_DECL void nng_http_conn_read_req(
- nng_http_conn *, nng_http_req *, nng_aio *);
-
-// nng_http_conn_read_res reads an entire response, EXCEPT for any entity
-// data. The caller is responsible for processing the headers in the response
-// and reading any submitted entity data itself.
-NNG_DECL void nng_http_conn_read_res(
- nng_http_conn *, nng_http_res *, nng_aio *);
-
-// nng_http_handler is a handler used on the server side to handle HTTP
-// requests coming into a specific URL.
-typedef struct nng_http_handler nng_http_handler;
-
-// nng_http_handler_alloc creates a server handler object, for the supplied
-// absolute URI (path only) with the callback. By default the handler
-// is assumed to handle only GET requests (and implictly HEAD requests
-// as well.)
-//
-// Note that methods which modify a handler cannot be called while the handler
-// is registered with the server, and that a handler can only be registered
-// once per server.
-//
-// The callback function will receive the following arguments (via
-// nng_aio_get_input(): nng_http_request *, nng_http_handler *, and
-// nng_http_conn *. The first is a request object, for convenience.
-// The second is the handler, from which the callback can obtain any other
-// data it has set. The final is the http connection, which can be used
-// to hijack the session.
-//
-// Upon completion, the handler should store an nng_http_res * as the
-// first output using nng_aio_set_output. If it does not do so, or supplies
-// NULL, then it must send a response itself.
-//
-// The callback should return 0 in most circumstances; if it returns anything
-// other than 0 then the connection is terminated (after possibly sending
-// a 500 error response to the client.)
-NNG_DECL int nng_http_handler_alloc(
- nng_http_handler **, const char *, void (*)(nng_aio *));
-
-// nng_http_handler_free frees the handler. This actually just drops a
-// reference count on the handler, as it may be in use by an existing
-// server. The server will also call this when it is destroyed.
-NNG_DECL void nng_http_handler_free(nng_http_handler *);
-
-// nng_http_handler_alloc_file creates a "file" based handler, that
-// serves up static content from the given file path. The content-type
-// supplied is determined from the file name using a simple built-in map.
-NNG_DECL int nng_http_handler_alloc_file(
- nng_http_handler **, const char *, const char *);
-
-// nng_http_handler_alloc_static creates a static-content handler.
-// The last argument is the content-type, which may be NULL (in which case
-// "application/octet-stream" is assumed.)
-NNG_DECL int nng_http_handler_alloc_static(
- nng_http_handler **, const char *, const void *, size_t, const char *);
-
-// nng_http_handler_alloc_file creates a "directory" based handler, that
-// serves up static content from the given directory tree. Directories
-// that contain an index.html or index.htm file use that file for the
-// directory content, otherwise a suitable error page is returned (the server
-// does not generate index pages automatically.) The content-type for
-// files is determined from the file name using a simple built-in map.
-NNG_DECL int nng_http_handler_alloc_directory(
- nng_http_handler **, const char *, const char *);
-
-// nng_http_handler_set_method sets the method that the handler will be
-// called for. By default this is GET. If NULL is supplied for the
-// method, then the handler is executed regardless of method, and must
-// inspect the method itself.
-NNG_DECL int nng_http_handler_set_method(nng_http_handler *, const char *);
-
-// nng_http_handler_set_host sets the Host: that the handler will be
-// called for (to allow for virtual hosts). If the value is NULL (the
-// default, then the Host: header is not considered when matching the
-// handler.) Note that the Host: header must match *exactly* (except
-// that case is not considered.)
-NNG_DECL int nng_http_handler_set_host(nng_http_handler *, const char *);
-
-// nng_http_handler_set_tree indicates that the handler is being registered
-// for a heirarchical tree, rather than just a single path, so it will be
-// called for all child paths supplied. By default the handler is only
-// called for an exact path match.
-NNG_DECL int nng_http_handler_set_tree(nng_http_handler *);
-
-// nng_http_handler_set_data is used to store additional data, along with
-// a possible clean up routine. (The clean up is a custom deallocator and
-// will be called with the supplied data as an argument, when the handler
-// is being deallocated.)
-NNG_DECL int nng_http_handler_set_data(
- nng_http_handler *, void *, void (*)(void *));
-
-// nng_http_handler_get_data returns the data that was previously stored.
-NNG_DECL void *nng_http_handler_get_data(nng_http_handler *);
-
-// nng_http_server is a handle to an HTTP server instance. Servers
-// only serve a single port / address at this time.
-
-typedef struct nng_http_server nng_http_server;
-
-// nng_http_server_hold gets a server structure, using the address determined
-// from the URL. If a server already exists, then a hold is placed on it, and
-// that instance is returned. If no such server exists, then a new instance
-// is created.
-NNG_DECL int nng_http_server_hold(nng_http_server **, const nng_url *);
-
-// nng_http_server_release releases the hold on the server. If this is the
-// last instance of the server, then it is shutdown and resources are freed.
-NNG_DECL void nng_http_server_release(nng_http_server *);
-
-// nng_http_server_start starts the server handling HTTP. Once this is
-// called, it will not be possible to change certain parameters (such as
-// any TLS configuration).
-NNG_DECL int nng_http_server_start(nng_http_server *);
-
-// nng_http_server_stop stops the server. No new client connections are
-// accepted after this returns.
-NNG_DECL void nng_http_server_stop(nng_http_server *);
-
-// nng_http_server_add_handler registers a handler on the server.
-// This function will return NNG_EADDRINUSE if a conflicting handler
-// is already registered (i.e. a handler with the same value for Host,
-// Method, and URL.)
-NNG_DECL int nng_http_server_add_handler(
- nng_http_server *, nng_http_handler *);
-
-// nni_http_del_handler removes the given handler. The caller is
-// responsible for finalizing it afterwards. If the handler was not found
-// (not registered), NNG_ENOENT is returned. In this case it is unsafe
-// to make assumptions about the validity of the handler.
-NNG_DECL int nng_http_server_del_handler(
- nng_http_server *, nng_http_handler *);
-
-// nng_http_server_set_tls adds a TLS configuration to the server,
-// and enables the use of it. This returns NNG_EBUSY if the server is
-// already started. This wipes out the entire TLS configuration on the
-// server client, so the caller must have configured it reasonably.
-// This API is not recommended unless the caller needs complete control
-// over the TLS configuration.
-NNG_DECL int nng_http_server_set_tls(nng_http_server *, nng_tls_config *);
-
-// nng_http_server_get_tls obtains the TLS configuration if one is present,
-// or returns NNG_EINVAL. The TLS configuration is invalidated if the
-// nng_http_server_set_tls function is called, so be careful.
-NNG_DECL int nng_http_server_get_tls(nng_http_server *, nng_tls_config **);
-
-// nng_http_hijack is intended to be called by a handler that wishes to
-// take over the processing of the HTTP session -- usually to change protocols
-// (such as in the case of websocket). The caller is responsible for the
-// final disposal of the associated nng_http_conn. Also, this completely
-// disassociates the http session from the server, so the server may be
-// stopped or destroyed without affecting the hijacked session. Note also
-// that the hijacker will need to issue any HTTP reply itself. Finally,
-// when a session is hijacked, the caller is also responsible for disposing
-// of the request structure. (Some hijackers may keep the request for
-// further processing.)
-
-NNG_DECL int nng_http_hijack(nng_http_conn *);
-
-// nng_http_client represents a "client" object. Clients can be used
-// to create HTTP connections. At present, connections are not cached
-// or reused, but that could change in the future.
-typedef struct nng_http_client nng_http_client;
-
-// nng_http_client_alloc allocates a client object, associated with
-// the given URL.
-NNG_DECL int nng_http_client_alloc(nng_http_client **, const nng_url *);
-
-// nng_http_client_free frees the client. Connections created by the
-// the client are not necessarily closed.
-NNG_DECL void nng_http_client_free(nng_http_client *);
-
-// nng_http_client_set_tls sets the TLS configuration. This wipes out
-// the entire TLS configuration on the client, so the caller must have
-// configured it reasonably. This API is not recommended unless the
-// caller needs complete control over the TLS configuration.
-NNG_DECL int nng_http_client_set_tls(nng_http_client *, nng_tls_config *);
-
-// nng_http_client_get_tls obtains the TLS configuration if one is present,
-// or returns NNG_EINVAL. The supplied TLS configuration object may
-// be invalidated by any future calls to nni_http_client_set_tls.
-NNG_DECL int nng_http_client_get_tls(nng_http_client *, nng_tls_config **);
-
-// nng_http_client_connect establishes a new connection with the server
-// named in the URL used when the client was created. Once the connection
-// is established, the associated nng_http_conn object pointer is returned
-// in the first (index 0) output for the aio.
-NNG_DECL void nng_http_client_connect(nng_http_client *, nng_aio *);
-
#ifdef __cplusplus
}
#endif
diff --git a/src/supplemental/http/CMakeLists.txt b/src/supplemental/http/CMakeLists.txt
index 9cfbd14a..98334109 100644
--- a/src/supplemental/http/CMakeLists.txt
+++ b/src/supplemental/http/CMakeLists.txt
@@ -1,6 +1,6 @@
#
-# Copyright 2017 Capitar IT Group BV <info@capitar.com>
-# Copyright 2017 Staysail Systems, Inc. <info@staysail.tech>
+# Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+# Copyright 2018 Capitar IT Group BV <info@capitar.com>
#
# This software is supplied under the terms of the MIT License, a
# copy of which should be located in the distribution where this
@@ -10,8 +10,11 @@
if (NNG_SUPP_HTTP)
set(HTTP_DEFINES -DNNG_SUPP_HTTP)
+ set(HTTP_HEADERS
+ supplemental/http/http.h)
set(HTTP_SOURCES
supplemental/http/http.h
+ supplemental/http/http_api.h
supplemental/http/http_client.c
supplemental/http/http_conn.c
supplemental/http/http_msg.c
@@ -20,7 +23,12 @@ if (NNG_SUPP_HTTP)
else()
set(HTTP_SOURCES
supplemental/http/http.h
+ supplemental/http/http_api.h
supplemental/http/http_public.c)
+ set(HTTP_HEADERS
+ supplemental/http/http.h)
endif()
+
set(NNG_DEFINES ${NNG_DEFINES} ${HTTP_DEFINES} PARENT_SCOPE)
set(NNG_SOURCES ${NNG_SOURCES} ${HTTP_SOURCES} PARENT_SCOPE)
+set(NNG_HEADERS ${NNG_HEADERS} ${HTTP_HEADERS} PARENT_SCOPE)
diff --git a/src/supplemental/http/http.h b/src/supplemental/http/http.h
index 7fadf705..fb96ce59 100644
--- a/src/supplemental/http/http.h
+++ b/src/supplemental/http/http.h
@@ -11,269 +11,443 @@
#ifndef NNG_SUPPLEMENTAL_HTTP_HTTP_H
#define NNG_SUPPLEMENTAL_HTTP_HTTP_H
-#include "core/nng_impl.h"
-
-#include <stdbool.h>
-
-typedef struct nng_http_req nni_http_req;
-typedef struct nng_http_res nni_http_res;
-typedef struct nng_http_conn nni_http_conn;
-typedef struct nng_http_handler nni_http_handler;
-typedef struct nng_http_server nni_http_server;
-typedef struct nng_http_client nni_http_client;
-
-// These functions are private to the internal framework, and really should
-// not be used elsewhere.
-extern int nni_http_req_init(nni_http_req **);
-extern void nni_http_req_reset(nni_http_req *);
-extern int nni_http_req_get_buf(nni_http_req *, void **, size_t *);
-extern int nni_http_req_parse(nni_http_req *, void *, size_t, size_t *);
-extern char *nni_http_req_headers(nni_http_req *);
-extern void nni_http_req_get_data(nni_http_req *, void **, size_t *);
-
-extern void nni_http_res_reset(nni_http_res *);
-extern int nni_http_res_get_buf(nni_http_res *, void **, size_t *);
-extern int nni_http_res_parse(nni_http_res *, void *, size_t, size_t *);
-extern void nni_http_res_get_data(nni_http_res *, void **, size_t *);
-extern char *nni_http_res_headers(nni_http_res *);
-
-// Private to the server. (Used to support session hijacking.)
-extern void nni_http_conn_set_ctx(nni_http_conn *, void *);
-extern void *nni_http_conn_get_ctx(nni_http_conn *);
-
-// An HTTP connection is a connection over which messages are exchanged.
-// Generally, clients send request messages, and then read responses.
-// Servers, read requests, and write responses. However, we do not
-// require a 1:1 mapping between request and response here -- the application
-// is responsible for dealing with that.
+// HTTP API. Only present if HTTP support compiled into the library.
+// Functions will return NNG_ENOTSUP (or NULL or 0 as appropriate)
+// if the library lacks support for HTTP.
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+
+// HTTP status codes. This list is not exhaustive.
+enum nng_http_status {
+ NNG_HTTP_STATUS_CONTINUE = 100,
+ NNG_HTTP_STATUS_SWITCHING = 101,
+ NNG_HTTP_STATUS_PROCESSING = 102,
+ NNG_HTTP_STATUS_OK = 200,
+ NNG_HTTP_STATUS_CREATED = 201,
+ NNG_HTTP_STATUS_ACCEPTED = 202,
+ NNG_HTTP_STATUS_NOT_AUTHORITATIVE = 203,
+ NNG_HTTP_STATUS_NO_CONTENT = 204,
+ NNG_HTTP_STATUS_RESET_CONTENT = 205,
+ NNG_HTTP_STATUS_PARTIAL_CONTENT = 206,
+ NNG_HTTP_STATUS_MULTI_STATUS = 207,
+ NNG_HTTP_STATUS_ALREADY_REPORTED = 208,
+ NNG_HTTP_STATUS_IM_USED = 226,
+ NNG_HTTP_STATUS_MULTIPLE_CHOICES = 300,
+ NNG_HTTP_STATUS_STATUS_MOVED_PERMANENTLY = 301,
+ NNG_HTTP_STATUS_FOUND = 302,
+ NNG_HTTP_STATUS_SEE_OTHER = 303,
+ NNG_HTTP_STATUS_NOT_MODIFIED = 304,
+ NNG_HTTP_STATUS_USE_PROXY = 305,
+ NNG_HTTP_STATUS_TEMPORARY_REDIRECT = 307,
+ NNG_HTTP_STATUS_PERMANENT_REDIRECT = 308,
+ NNG_HTTP_STATUS_BAD_REQUEST = 400,
+ NNG_HTTP_STATUS_UNAUTHORIZED = 401,
+ NNG_HTTP_STATUS_PAYMENT_REQUIRED = 402,
+ NNG_HTTP_STATUS_FORBIDDEN = 403,
+ NNG_HTTP_STATUS_NOT_FOUND = 404,
+ NNG_HTTP_STATUS_METHOD_NOT_ALLOWED = 405,
+ NNG_HTTP_STATUS_NOT_ACCEPTABLE = 406,
+ NNG_HTTP_STATUS_PROXY_AUTH_REQUIRED = 407,
+ NNG_HTTP_STATUS_REQUEST_TIMEOUT = 408,
+ NNG_HTTP_STATUS_CONFLICT = 409,
+ NNG_HTTP_STATUS_GONE = 410,
+ NNG_HTTP_STATUS_LENGTH_REQUIRED = 411,
+ NNG_HTTP_STATUS_PRECONDITION_FAILED = 412,
+ NNG_HTTP_STATUS_PAYLOAD_TOO_LARGE = 413,
+ NNG_HTTP_STATUS_ENTITY_TOO_LONG = 414,
+ NNG_HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE = 415,
+ NNG_HTTP_STATUS_RANGE_NOT_SATISFIABLE = 416,
+ NNG_HTTP_STATUS_EXPECTATION_FAILED = 417,
+ NNG_HTTP_STATUS_TEAPOT = 418,
+ NNG_HTTP_STATUS_UNPROCESSABLE_ENTITY = 422,
+ NNG_HTTP_STATUS_LOCKED = 423,
+ NNG_HTTP_STATUS_FAILED_DEPENDENCY = 424,
+ NNG_HTTP_STATUS_UPGRADE_REQUIRED = 426,
+ NNG_HTTP_STATUS_PRECONDITION_REQUIRED = 428,
+ NNG_HTTP_STATUS_TOO_MANY_REQUESTS = 429,
+ NNG_HTTP_STATUS_HEADERS_TOO_LARGE = 431,
+ NNG_HTTP_STATUS_UNAVAIL_LEGAL_REASONS = 451,
+ NNG_HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
+ NNG_HTTP_STATUS_NOT_IMPLEMENTED = 501,
+ NNG_HTTP_STATUS_BAD_GATEWAY = 502,
+ NNG_HTTP_STATUS_SERVICE_UNAVAILABLE = 503,
+ NNG_HTTP_STATUS_GATEWAY_TIMEOUT = 504,
+ NNG_HTTP_STATUS_HTTP_VERSION_NOT_SUPP = 505,
+ NNG_HTTP_STATUS_VARIANT_ALSO_NEGOTIATES = 506,
+ NNG_HTTP_STATUS_INSUFFICIENT_STORAGE = 507,
+ NNG_HTTP_STATUS_LOOP_DETECTED = 508,
+ NNG_HTTP_STATUS_NOT_EXTENDED = 510,
+ NNG_HTTP_STATUS_NETWORK_AUTH_REQUIRED = 511,
+};
+
+// nng_http_req represents an HTTP request.
+typedef struct nng_http_req nng_http_req;
+
+// nng_http_req_alloc creates a vanilla HTTP request object. The object is
+// initialized with the given URL object for an HTTP/1.1 GET request by
+// default. It also adds the Host: header required for HTTP/1.1. If the
+// url is NULL, then the uri and Host: header are uninitialized, and will
+// need to be set explicitly.
+NNG_DECL int nng_http_req_alloc(nng_http_req **, const nng_url *);
+
+// nng_http_req_free frees an HTTP request object.
+NNG_DECL void nng_http_req_free(nng_http_req *);
+
+// nng_http_req_get_method returns the method.
+NNG_DECL const char *nng_http_req_get_method(nng_http_req *);
+
+// nng_http_req_get_version returns the version, usually HTTP/1.1.
+NNG_DECL const char *nng_http_req_get_version(nng_http_req *);
+
+// nng_http_req_get_uri returns the "abs-uri", which is URL without
+// the scheme, host, or port.
+NNG_DECL const char *nng_http_req_get_uri(nng_http_req *);
+
+// nng_http_req_set_header sets an HTTP header, replacing any previous value
+// that might have been present.
+NNG_DECL int nng_http_req_set_header(
+ nng_http_req *, const char *, const char *);
+
+// nng_http_req_add_header adds an HTTP header, without disrupting any other
+// with the same name that might have been present.
+NNG_DECL int nng_http_req_add_header(
+ nng_http_req *, const char *, const char *);
+
+// nng_http_req_del_header deletes all occurrences of a named header.
+NNG_DECL int nng_http_req_del_header(nng_http_req *, const char *);
+
+// nng_http_req_get_header looks up a header with the named, returns NULL
+// if not found.
+NNG_DECL const char *nng_http_req_get_header(nng_http_req *, const char *);
+
+// nng_http_req_set_method is used to change the method of a request.
+// The method should be an upper case HTTP method, like POST, or DELETE.
+// Null sets the default ("GET").
+NNG_DECL int nng_http_req_set_method(nng_http_req *, const char *);
+
+// nng_http_req_set_version is used to change the version of a request.
+// Normally the version is "HTTP/1.1". Note that the framework does
+// not support HTTP/2 at all. Null sets the default ("HTTP/1.1").
+NNG_DECL int nng_http_req_set_version(nng_http_req *, const char *);
+
+// nng_http_req_set_uri is used to change the URI of a request. This
+// should be an "abs-uri", that is a path, plus query and fragment if
+// needed. The scheme, host, and port don't belong here. The URI should
+// start with a leading '/' per HTTP.
+NNG_DECL int nng_http_req_set_uri(nng_http_req *, const char *);
+
+// nng_http_req_set_data adds entity data to the request. The
+// data object must persist (so only really useful for static data).
+// The content-length header is updated as well, but the caller should
+// probably set the content-type header.
+NNG_DECL int nng_http_req_set_data(nng_http_req *, const void *, size_t);
+
+// nng_http_req_copy_data adds entity data to the response. A private
+// copy of the data is made (will be freed with the request).
+// The content-length header is updated as well, but the caller should
+// probably set the content-type header.
+NNG_DECL int nng_http_req_copy_data(nng_http_req *, const void *, size_t);
+
+// nng_http_res represents an HTTP response.
+typedef struct nng_http_res nng_http_res;
+
+// nng_http_res_alloc creates a vanilla HTTP response object. The object is
+// initialized for an HTTP/1.1 200 OK response by default.
+NNG_DECL int nng_http_res_alloc(nng_http_res **);
+
+// nng_http_res_alloc_error creates an error HTTP response object. The object
+// is initialized for an HTTP/1.1 response, and contains an associated
+// generic HTML error page.
+NNG_DECL int nng_http_res_alloc_error(nng_http_res **, uint16_t);
+
+// nng_http_res_free frees an HTTP response object.
+NNG_DECL void nng_http_res_free(nng_http_res *);
+
+// nng_http_res_get_status returns the HTTP status code from the server.
+NNG_DECL uint16_t nng_http_res_get_status(nng_http_res *);
+
+// nng_http_res_set_status sets the HTTP status code.
+NNG_DECL int nng_http_res_set_status(nng_http_res *, uint16_t);
+
+// nng_http_res_get_reason returns the human readable status message
+// that the server responds (or responded) with.
+NNG_DECL const char *nng_http_res_get_reason(nng_http_res *);
+
+// nng_http_res_set_rason sets the human readable status message.
+// NULL means that a default reason is used based on the status code.
+NNG_DECL int nng_http_res_set_reason(nng_http_res *, const char *);
+
+// nng_http_res_set_header sets an HTTP header, replacing any previous value
+// that might have been present.
+NNG_DECL int nng_http_res_set_header(
+ nng_http_res *, const char *, const char *);
+
+// nng_http_res_add_header adds an HTTP header, without disrupting any other
+// with the same name that might have been present.
+NNG_DECL int nng_http_res_add_header(
+ nng_http_res *, const char *, const char *);
+
+// nng_http_res_del_header deletes all occurrences of a named header.
+NNG_DECL int nng_http_res_del_header(nng_http_res *, const char *);
+
+// nng_http_res_get_header looks up a header with the named, returns NULL
+// if not found.
+NNG_DECL const char *nng_http_res_get_header(nng_http_res *, const char *);
+
+// nng_http_res_set_version is used to change the version of a response.
+// Normally the version is "HTTP/1.1". Note that the framework does
+// not support HTTP/2 at all. NULL sets the default ("HTTP/1.1").
+NNG_DECL int nng_http_res_set_version(nng_http_res *, const char *);
+
+// nng_http_res_get_version returns the version, usually HTTP/1.1.
+NNG_DECL const char *nng_http_res_get_version(nng_http_res *);
+
+// nng_http_res_set_data adds entity data to the response. The
+// data object must persist (so only really useful for static data).
+// The content-length header is updated as well, but the caller should
+// probably set the content-type header.
+NNG_DECL int nng_http_res_set_data(nng_http_res *, const void *, size_t);
+
+// nng_http_res_copy_data adds entity data to the response. A private
+// copy of the data is made (will be freed with the request).
+// The content-length header is updated as well, but the caller should
+// probably set the content-type header.
+NNG_DECL int nng_http_res_copy_data(nng_http_res *, const void *, size_t);
+
+// An nng_http_conn represents an underlying "connection". It may be
+// a TCP channel, or a TLS channel, but the main thing is that this is
+// normally only used for exchanging HTTP requests and responses.
+typedef struct nng_http_conn nng_http_conn;
+
+// nng_http_conn_close closes the underlying channel. Applications should
+// not use this channel after this operation is performed.
+NNG_DECL void nng_http_conn_close(nng_http_conn *);
+
+// nng_http_conn_read attempts to read data from the connection. This
+// completes as soon as at least one byte is read; it does not wait
+// for the entire aio to be filled.
+NNG_DECL void nng_http_conn_read(nng_http_conn *, nng_aio *);
+
+// nng_http_conn_read_all is like nng_http_conn_read, but it does not
+// finish until either all the requested data is read, or an error occurs.
+NNG_DECL void nng_http_conn_read_all(nng_http_conn *, nng_aio *);
+
+// nng_http_conn_write attempts to write data, but it can write less
+// than the amount requested. (It completes as soon as at least one
+// byte is written.)
+NNG_DECL void nng_http_conn_write(nng_http_conn *, nng_aio *);
+
+// nng_http_conn_write_all is like nng_http_conn_write, but it does not
+// finish until either all the requested data is written, or an error occurs.
+NNG_DECL void nng_http_conn_write_all(nng_http_conn *, nng_aio *);
+
+// nng_http_conn_write_req writes the entire request. It will also write any
+// data that has been attached.
+NNG_DECL void nng_http_conn_write_req(
+ nng_http_conn *, nng_http_req *, nng_aio *);
+
+// nng_http_conn_write_res writes the entire response. It will also write any
+// data that has been attached.
+NNG_DECL void nng_http_conn_write_res(
+ nng_http_conn *, nng_http_res *, nng_aio *);
+
+// nng_http_conn_read_req reads an entire request, EXCEPT for any entity
+// data. The caller is responsible for processing the headers in the request
+// and reading any submitted entity data itself.
+NNG_DECL void nng_http_conn_read_req(
+ nng_http_conn *, nng_http_req *, nng_aio *);
+
+// nng_http_conn_read_res reads an entire response, EXCEPT for any entity
+// data. The caller is responsible for processing the headers in the response
+// and reading any submitted entity data itself.
+NNG_DECL void nng_http_conn_read_res(
+ nng_http_conn *, nng_http_res *, nng_aio *);
+
+// nng_http_handler is a handler used on the server side to handle HTTP
+// requests coming into a specific URL.
+typedef struct nng_http_handler nng_http_handler;
+
+// nng_http_handler_alloc creates a server handler object, for the supplied
+// absolute URI (path only) with the callback. By default the handler
+// is assumed to handle only GET requests (and implictly HEAD requests
+// as well.)
//
-// We only support HTTP/1.1, though using the nni_http_conn_read and
-// nni_http_conn_write low level methods, it is possible to write an upgrader
-// (such as websocket!) that might support e.g. HTTP/2 or reading data that
-// follows a legacy HTTP/1.0 message.
+// Note that methods which modify a handler cannot be called while the handler
+// is registered with the server, and that a handler can only be registered
+// once per server.
+//
+// The callback function will receive the following arguments (via
+// nng_aio_get_input(): nng_http_request *, nng_http_handler *, and
+// nng_http_conn *. The first is a request object, for convenience.
+// The second is the handler, from which the callback can obtain any other
+// data it has set. The final is the http connection, which can be used
+// to hijack the session.
+//
+// Upon completion, the handler should store an nng_http_res * as the
+// first output using nng_aio_set_output. If it does not do so, or supplies
+// NULL, then it must send a response itself.
//
-// Any error on the connection, including cancellation of a request, is fatal
-// the connection.
-
-// These initialization functions create stream for HTTP transactions.
-// They should only be used by the server or client HTTP implementations,
-// and are not for use by other code.
-extern int nni_http_conn_init_tcp(nni_http_conn **, void *);
-extern int nni_http_conn_init_tls(nni_http_conn **, nng_tls_config *, void *);
-
-extern void nni_http_conn_close(nni_http_conn *);
-extern void nni_http_conn_fini(nni_http_conn *);
-
-// Reading messages -- the caller must supply a preinitialized (but otherwise
-// idle) message. We recommend the caller store this in the aio's user data.
-// Note that the iovs of the aio's are clobbered by these methods -- callers
-// must not use them for any other purpose.
-
-extern int nni_http_req_alloc(nni_http_req **, const nni_url *);
-extern int nni_http_res_alloc(nni_http_res **);
-extern int nni_http_res_alloc_error(nni_http_res **, uint16_t);
-extern void nni_http_req_free(nni_http_req *);
-extern void nni_http_res_free(nni_http_res *);
-extern void nni_http_write_req(nni_http_conn *, nni_http_req *, nni_aio *);
-extern void nni_http_write_res(nni_http_conn *, nni_http_res *, nni_aio *);
-extern void nni_http_read_req(nni_http_conn *, nni_http_req *, nni_aio *);
-extern void nni_http_read_res(nni_http_conn *, nni_http_res *, nni_aio *);
-
-extern const char *nni_http_req_get_header(nni_http_req *, const char *);
-extern const char *nni_http_res_get_header(nni_http_res *, const char *);
-extern int nni_http_req_add_header(nni_http_req *, const char *, const char *);
-extern int nni_http_res_add_header(nni_http_res *, const char *, const char *);
-extern int nni_http_req_set_header(nni_http_req *, const char *, const char *);
-extern int nni_http_res_set_header(nni_http_res *, const char *, const char *);
-extern int nni_http_req_del_header(nni_http_req *, const char *);
-extern int nni_http_res_del_header(nni_http_res *, const char *);
-extern int nni_http_req_copy_data(nni_http_req *, const void *, size_t);
-extern int nni_http_res_copy_data(nni_http_res *, const void *, size_t);
-extern int nni_http_req_set_data(nni_http_req *, const void *, size_t);
-extern int nni_http_res_set_data(nni_http_res *, const void *, size_t);
-extern const char *nni_http_req_get_method(nni_http_req *);
-extern const char *nni_http_req_get_version(nni_http_req *);
-extern const char *nni_http_req_get_uri(nni_http_req *);
-extern int nni_http_req_set_method(nni_http_req *, const char *);
-extern int nni_http_req_set_version(nni_http_req *, const char *);
-extern int nni_http_req_set_uri(nni_http_req *, const char *);
-extern uint16_t nni_http_res_get_status(nni_http_res *);
-extern int nni_http_res_set_status(nni_http_res *, uint16_t);
-extern const char *nni_http_res_get_version(nni_http_res *);
-extern int nni_http_res_set_version(nni_http_res *, const char *);
-extern const char *nni_http_res_get_reason(nni_http_res *);
-extern int nni_http_res_set_reason(nni_http_res *, const char *);
-
-extern void nni_http_read(nni_http_conn *, nni_aio *);
-extern void nni_http_read_full(nni_http_conn *, nni_aio *);
-extern void nni_http_write(nni_http_conn *, nni_aio *);
-extern void nni_http_write_full(nni_http_conn *, nni_aio *);
-extern int nni_http_sock_addr(nni_http_conn *, nni_sockaddr *);
-extern int nni_http_peer_addr(nni_http_conn *, nni_sockaddr *);
-
-// nni_tls_http_verified returns true if the peer has been verified using TLS.
-extern bool nni_http_tls_verified(nni_http_conn *);
-
-// nni_http_server will look for an existing server with the same
-// name and port, or create one if one does not exist. The servers
-// are reference counted to permit sharing the server object across
-// multiple subsystems. The URL hostname matching is very limited,
-// and the names must match *exactly* (without DNS resolution). Unless
-// a restricted binding is required, we recommend using a URL consisting
-// of an empty host name, such as http:// or https:// -- this would
-// convert to binding to the default port on all interfaces on the host.
-extern int nni_http_server_init(nni_http_server **, const nni_url *);
-
-// nni_http_server_fini drops the reference count on the server, and
-// if this was the last reference, closes down the server and frees
-// all related resources. It will not affect hijacked connections.
-extern void nni_http_server_fini(nni_http_server *);
-
-// nni_http_server_add_handler registers a handler on the server.
+// The callback should return 0 in most circumstances; if it returns anything
+// other than 0 then the connection is terminated (after possibly sending
+// a 500 error response to the client.)
+NNG_DECL int nng_http_handler_alloc(
+ nng_http_handler **, const char *, void (*)(nng_aio *));
+
+// nng_http_handler_free frees the handler. This actually just drops a
+// reference count on the handler, as it may be in use by an existing
+// server. The server will also call this when it is destroyed.
+NNG_DECL void nng_http_handler_free(nng_http_handler *);
+
+// nng_http_handler_alloc_file creates a "file" based handler, that
+// serves up static content from the given file path. The content-type
+// supplied is determined from the file name using a simple built-in map.
+NNG_DECL int nng_http_handler_alloc_file(
+ nng_http_handler **, const char *, const char *);
+
+// nng_http_handler_alloc_static creates a static-content handler.
+// The last argument is the content-type, which may be NULL (in which case
+// "application/octet-stream" is assumed.)
+NNG_DECL int nng_http_handler_alloc_static(
+ nng_http_handler **, const char *, const void *, size_t, const char *);
+
+// nng_http_handler_alloc_file creates a "directory" based handler, that
+// serves up static content from the given directory tree. Directories
+// that contain an index.html or index.htm file use that file for the
+// directory content, otherwise a suitable error page is returned (the server
+// does not generate index pages automatically.) The content-type for
+// files is determined from the file name using a simple built-in map.
+NNG_DECL int nng_http_handler_alloc_directory(
+ nng_http_handler **, const char *, const char *);
+
+// nng_http_handler_set_method sets the method that the handler will be
+// called for. By default this is GET. If NULL is supplied for the
+// method, then the handler is executed regardless of method, and must
+// inspect the method itself.
+NNG_DECL int nng_http_handler_set_method(nng_http_handler *, const char *);
+
+// nng_http_handler_set_host sets the Host: that the handler will be
+// called for (to allow for virtual hosts). If the value is NULL (the
+// default, then the Host: header is not considered when matching the
+// handler.) Note that the Host: header must match *exactly* (except
+// that case is not considered.)
+NNG_DECL int nng_http_handler_set_host(nng_http_handler *, const char *);
+
+// nng_http_handler_set_tree indicates that the handler is being registered
+// for a heirarchical tree, rather than just a single path, so it will be
+// called for all child paths supplied. By default the handler is only
+// called for an exact path match.
+NNG_DECL int nng_http_handler_set_tree(nng_http_handler *);
+
+// nng_http_handler_set_data is used to store additional data, along with
+// a possible clean up routine. (The clean up is a custom deallocator and
+// will be called with the supplied data as an argument, when the handler
+// is being deallocated.)
+NNG_DECL int nng_http_handler_set_data(
+ nng_http_handler *, void *, void (*)(void *));
+
+// nng_http_handler_get_data returns the data that was previously stored.
+NNG_DECL void *nng_http_handler_get_data(nng_http_handler *);
+
+// nng_http_server is a handle to an HTTP server instance. Servers
+// only serve a single port / address at this time.
+
+typedef struct nng_http_server nng_http_server;
+
+// nng_http_server_hold gets a server structure, using the address determined
+// from the URL. If a server already exists, then a hold is placed on it, and
+// that instance is returned. If no such server exists, then a new instance
+// is created.
+NNG_DECL int nng_http_server_hold(nng_http_server **, const nng_url *);
+
+// nng_http_server_release releases the hold on the server. If this is the
+// last instance of the server, then it is shutdown and resources are freed.
+NNG_DECL void nng_http_server_release(nng_http_server *);
+
+// nng_http_server_start starts the server handling HTTP. Once this is
+// called, it will not be possible to change certain parameters (such as
+// any TLS configuration).
+NNG_DECL int nng_http_server_start(nng_http_server *);
+
+// nng_http_server_stop stops the server. No new client connections are
+// accepted after this returns.
+NNG_DECL void nng_http_server_stop(nng_http_server *);
+
+// nng_http_server_add_handler registers a handler on the server.
// This function will return NNG_EADDRINUSE if a conflicting handler
// is already registered (i.e. a handler with the same value for Host,
// Method, and URL.)
-extern int nni_http_server_add_handler(nni_http_server *, nni_http_handler *);
+NNG_DECL int nng_http_server_add_handler(
+ nng_http_server *, nng_http_handler *);
// nni_http_del_handler removes the given handler. The caller is
// responsible for finalizing it afterwards. If the handler was not found
// (not registered), NNG_ENOENT is returned. In this case it is unsafe
// to make assumptions about the validity of the handler.
-extern int nni_http_server_del_handler(nni_http_server *, nni_http_handler *);
+NNG_DECL int nng_http_server_del_handler(
+ nng_http_server *, nng_http_handler *);
-// nni_http_server_set_tls adds a TLS configuration to the server,
+// nng_http_server_set_tls adds a TLS configuration to the server,
// and enables the use of it. This returns NNG_EBUSY if the server is
// already started. This wipes out the entire TLS configuration on the
// server client, so the caller must have configured it reasonably.
// This API is not recommended unless the caller needs complete control
// over the TLS configuration.
-extern int nni_http_server_set_tls(nni_http_server *, nng_tls_config *);
+NNG_DECL int nng_http_server_set_tls(nng_http_server *, nng_tls_config *);
-// nni_http_server_get_tls obtains the TLS configuration if one is present,
+// nng_http_server_get_tls obtains the TLS configuration if one is present,
// or returns NNG_EINVAL. The TLS configuration is invalidated if the
-// nni_http_server_set_tls function is called, so be careful.
-extern int nni_http_server_get_tls(nni_http_server *, nng_tls_config **);
-
-// nni_http_server_start starts listening on the supplied port.
-extern int nni_http_server_start(nni_http_server *);
+// nng_http_server_set_tls function is called, so be careful.
+NNG_DECL int nng_http_server_get_tls(nng_http_server *, nng_tls_config **);
-// nni_http_server_stop stops the server, closing the listening socket.
-// Connections that have been "upgraded" are unaffected. Connections
-// associated with a callback will complete their callback, and then close.
-extern void nni_http_server_stop(nni_http_server *);
-
-// nni_http_hijack is intended to be called by a handler that wishes to
+// nng_http_hijack is intended to be called by a handler that wishes to
// take over the processing of the HTTP session -- usually to change protocols
-// (such as in the case of websocket). The caller is responsible for obtaining
-// and disposal of the associated nni_http session. Also, this completely
+// (such as in the case of websocket). The caller is responsible for the
+// final disposal of the associated nng_http_conn. Also, this completely
// disassociates the http session from the server, so the server may be
// stopped or destroyed without affecting the hijacked session. Note also
// that the hijacker will need to issue any HTTP reply itself. Finally,
// when a session is hijacked, the caller is also responsible for disposing
// of the request structure. (Some hijackers may keep the request for
// further processing.)
-extern int nni_http_hijack(nni_http_conn *);
-// nni_http_handler_init creates a server handler object, for the supplied
-// URI (path only) with the callback.
-//
-// Note that methods which modify a handler cannot be called while the handler
-// is registered with the server, and that a handler can only be registered
-// once per server.
-//
-// The callback function will receive the following arguments (via
-// nng_aio_get_input(): nni_http_request *, nni_http_handler *, and
-// nni_http_context_t *. The first is a request object, for convenience.
-// The second is the handler, from which the callback can obtain any other
-// data it has set. The final is the http context, from which its possible
-// to hijack the session.
-extern int nni_http_handler_init(
- nni_http_handler **, const char *, void (*)(nni_aio *));
-
-// nni_http_handler_init_file creates a handler with a function to serve
-// up a file named in the last argument.
-extern int nni_http_handler_init_file(
- nni_http_handler **, const char *, const char *);
-
-// nni_http_handler_init_file_ctype is like nni_http_handler_init_file, but
-// provides for setting the Content-Type explicitly (last argument).
-extern int nni_http_handler_init_file_ctype(
- nni_http_handler **, const char *, const char *, const char *);
-
-// nni_http_handler_init_directory arranges to serve up an entire
-// directory tree. The content types are determined from the built-in
-// content type list. Actual directories are required to contain a
-// file called index.html or index.htm. We do not generate directory
-// listings for security reasons.
-extern int nni_http_handler_init_directory(
- nni_http_handler **, const char *, const char *);
-
-// nni_http_handler_init_static creates a handler that serves up static content
-// supplied, with the Content-Type supplied in the final argument.
-extern int nni_http_handler_init_static(
- nni_http_handler **, const char *, const void *, size_t, const char *);
-
-// nni_http_handler_fini destroys a handler. This should only be done before
-// the handler is added, or after it is deleted. The server automatically
-// calls this for any handlers still registered with it if it is destroyed.
-extern void nni_http_handler_fini(nni_http_handler *);
-
-// nni_http_handler_set_tree marks the handler as servicing the entire
-// tree (e.g. a directory), rather than just a leaf node. The handler
-// will probably need to inspect the URL of the request.
-extern int nni_http_handler_set_tree(nni_http_handler *);
-
-// nni_http_handler_set_host limits the handler to only being called for
-// the given Host: field. This can be used to set up multiple virtual
-// hosts. Note that host names must match exactly. If NULL or an empty
-// string is specified, then the client's Host: field is ignored. (The
-// supplied value for the Host is copied by this function.) When supplying
-// a hostname, do not include a value for the port number; we do not match
-// on port number as we assume that clients MUST have gotten that part right
-// as we do not support virtual hosting on multiple separate ports; the
-// server only listens on a single port.
-extern int nni_http_handler_set_host(nni_http_handler *, const char *);
-
-// nni_http_handler_set_method limits the handler to only being called
-// for the given HTTP method. By default a handler is called for GET
-// methods only (and HEAD, which is handled internally.) Handlers can
-// be specified for any valid HTTP method. A handler may set the value
-// NULL here, to be called for any HTTP method. In such a case, the handler
-// is obligated to inspect the method. (Note: the passed method must be
-// in upper case and should come from a statically allocated string; the
-// server does not make its own copy.)
-extern int nni_http_handler_set_method(nni_http_handler *, const char *);
-
-// nni_http_handler_set_data sets an opaque data element on the handler,
-// which will be available to the callback via nni_http_handler_get_data.
-// The callback is an optional destructor, and will be called with the
-// data as its argument, when the handler is being destroyed.
-extern int nni_http_handler_set_data(nni_http_handler *, void *, nni_cb);
-
-// nni_http_handler_get_data returns the data that was previously stored
-// at that index. It returns NULL if no data was set, or an invalid index
-// is supplied.
-extern void *nni_http_handler_get_data(nni_http_handler *);
-
-// nni_http_handler_get_uri returns the URI set on the handler.
-extern const char *nni_http_handler_get_uri(nni_http_handler *);
-
-// Client stuff.
-
-extern int nni_http_client_init(nni_http_client **, const nni_url *);
-extern void nni_http_client_fini(nni_http_client *);
-
-// nni_http_client_set_tls sets the TLS configuration. This wipes out
+NNG_DECL int nng_http_hijack(nng_http_conn *);
+
+// nng_http_client represents a "client" object. Clients can be used
+// to create HTTP connections. At present, connections are not cached
+// or reused, but that could change in the future.
+typedef struct nng_http_client nng_http_client;
+
+// nng_http_client_alloc allocates a client object, associated with
+// the given URL.
+NNG_DECL int nng_http_client_alloc(nng_http_client **, const nng_url *);
+
+// nng_http_client_free frees the client. Connections created by the
+// the client are not necessarily closed.
+NNG_DECL void nng_http_client_free(nng_http_client *);
+
+// nng_http_client_set_tls sets the TLS configuration. This wipes out
// the entire TLS configuration on the client, so the caller must have
// configured it reasonably. This API is not recommended unless the
// caller needs complete control over the TLS configuration.
-extern int nni_http_client_set_tls(nni_http_client *, nng_tls_config *);
+NNG_DECL int nng_http_client_set_tls(nng_http_client *, nng_tls_config *);
-// nni_http_client_get_tls obtains the TLS configuration if one is present,
+// nng_http_client_get_tls obtains the TLS configuration if one is present,
// or returns NNG_EINVAL. The supplied TLS configuration object may
// be invalidated by any future calls to nni_http_client_set_tls.
-extern int nni_http_client_get_tls(nni_http_client *, nng_tls_config **);
+NNG_DECL int nng_http_client_get_tls(nng_http_client *, nng_tls_config **);
+
+// nng_http_client_connect establishes a new connection with the server
+// named in the URL used when the client was created. Once the connection
+// is established, the associated nng_http_conn object pointer is returned
+// in the first (index 0) output for the aio.
+NNG_DECL void nng_http_client_connect(nng_http_client *, nng_aio *);
-extern void nni_http_client_connect(nni_http_client *, nni_aio *);
+#ifdef __cplusplus
+}
+#endif
-#endif // NNG_SUPPLEMENTAL_HTTP_HTTP_H
+#endif // NNG_H
diff --git a/src/supplemental/http/http_api.h b/src/supplemental/http/http_api.h
new file mode 100644
index 00000000..31c54146
--- /dev/null
+++ b/src/supplemental/http/http_api.h
@@ -0,0 +1,283 @@
+//
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
+//
+// 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.
+//
+
+#ifndef NNG_SUPPLEMENTAL_HTTP_HTTP_API_H
+#define NNG_SUPPLEMENTAL_HTTP_HTTP_API_H
+
+#include "core/nng_impl.h"
+#include "supplemental/http/http.h"
+
+// This represents the "internal" HTTP API. It should not be used
+// or exposed to applications directly.
+
+#include <stdbool.h>
+
+typedef struct nng_http_req nni_http_req;
+typedef struct nng_http_res nni_http_res;
+typedef struct nng_http_conn nni_http_conn;
+typedef struct nng_http_handler nni_http_handler;
+typedef struct nng_http_server nni_http_server;
+typedef struct nng_http_client nni_http_client;
+
+// These functions are private to the internal framework, and really should
+// not be used elsewhere.
+extern int nni_http_req_init(nni_http_req **);
+extern void nni_http_req_reset(nni_http_req *);
+extern int nni_http_req_get_buf(nni_http_req *, void **, size_t *);
+extern int nni_http_req_parse(nni_http_req *, void *, size_t, size_t *);
+extern char *nni_http_req_headers(nni_http_req *);
+extern void nni_http_req_get_data(nni_http_req *, void **, size_t *);
+
+extern void nni_http_res_reset(nni_http_res *);
+extern int nni_http_res_get_buf(nni_http_res *, void **, size_t *);
+extern int nni_http_res_parse(nni_http_res *, void *, size_t, size_t *);
+extern void nni_http_res_get_data(nni_http_res *, void **, size_t *);
+extern char *nni_http_res_headers(nni_http_res *);
+
+// Private to the server. (Used to support session hijacking.)
+extern void nni_http_conn_set_ctx(nni_http_conn *, void *);
+extern void *nni_http_conn_get_ctx(nni_http_conn *);
+
+// An HTTP connection is a connection over which messages are exchanged.
+// Generally, clients send request messages, and then read responses.
+// Servers, read requests, and write responses. However, we do not
+// require a 1:1 mapping between request and response here -- the application
+// is responsible for dealing with that.
+//
+// We only support HTTP/1.1, though using the nni_http_conn_read and
+// nni_http_conn_write low level methods, it is possible to write an upgrader
+// (such as websocket!) that might support e.g. HTTP/2 or reading data that
+// follows a legacy HTTP/1.0 message.
+//
+// Any error on the connection, including cancellation of a request, is fatal
+// the connection.
+
+// These initialization functions create stream for HTTP transactions.
+// They should only be used by the server or client HTTP implementations,
+// and are not for use by other code.
+extern int nni_http_conn_init_tcp(nni_http_conn **, void *);
+extern int nni_http_conn_init_tls(nni_http_conn **, nng_tls_config *, void *);
+
+extern void nni_http_conn_close(nni_http_conn *);
+extern void nni_http_conn_fini(nni_http_conn *);
+
+// Reading messages -- the caller must supply a preinitialized (but otherwise
+// idle) message. We recommend the caller store this in the aio's user data.
+// Note that the iovs of the aio's are clobbered by these methods -- callers
+// must not use them for any other purpose.
+
+extern int nni_http_req_alloc(nni_http_req **, const nni_url *);
+extern int nni_http_res_alloc(nni_http_res **);
+extern int nni_http_res_alloc_error(nni_http_res **, uint16_t);
+extern void nni_http_req_free(nni_http_req *);
+extern void nni_http_res_free(nni_http_res *);
+extern void nni_http_write_req(nni_http_conn *, nni_http_req *, nni_aio *);
+extern void nni_http_write_res(nni_http_conn *, nni_http_res *, nni_aio *);
+extern void nni_http_read_req(nni_http_conn *, nni_http_req *, nni_aio *);
+extern void nni_http_read_res(nni_http_conn *, nni_http_res *, nni_aio *);
+
+extern const char *nni_http_req_get_header(nni_http_req *, const char *);
+extern const char *nni_http_res_get_header(nni_http_res *, const char *);
+extern int nni_http_req_add_header(nni_http_req *, const char *, const char *);
+extern int nni_http_res_add_header(nni_http_res *, const char *, const char *);
+extern int nni_http_req_set_header(nni_http_req *, const char *, const char *);
+extern int nni_http_res_set_header(nni_http_res *, const char *, const char *);
+extern int nni_http_req_del_header(nni_http_req *, const char *);
+extern int nni_http_res_del_header(nni_http_res *, const char *);
+extern int nni_http_req_copy_data(nni_http_req *, const void *, size_t);
+extern int nni_http_res_copy_data(nni_http_res *, const void *, size_t);
+extern int nni_http_req_set_data(nni_http_req *, const void *, size_t);
+extern int nni_http_res_set_data(nni_http_res *, const void *, size_t);
+extern const char *nni_http_req_get_method(nni_http_req *);
+extern const char *nni_http_req_get_version(nni_http_req *);
+extern const char *nni_http_req_get_uri(nni_http_req *);
+extern int nni_http_req_set_method(nni_http_req *, const char *);
+extern int nni_http_req_set_version(nni_http_req *, const char *);
+extern int nni_http_req_set_uri(nni_http_req *, const char *);
+extern uint16_t nni_http_res_get_status(nni_http_res *);
+extern int nni_http_res_set_status(nni_http_res *, uint16_t);
+extern const char *nni_http_res_get_version(nni_http_res *);
+extern int nni_http_res_set_version(nni_http_res *, const char *);
+extern const char *nni_http_res_get_reason(nni_http_res *);
+extern int nni_http_res_set_reason(nni_http_res *, const char *);
+
+extern void nni_http_read(nni_http_conn *, nni_aio *);
+extern void nni_http_read_full(nni_http_conn *, nni_aio *);
+extern void nni_http_write(nni_http_conn *, nni_aio *);
+extern void nni_http_write_full(nni_http_conn *, nni_aio *);
+extern int nni_http_sock_addr(nni_http_conn *, nni_sockaddr *);
+extern int nni_http_peer_addr(nni_http_conn *, nni_sockaddr *);
+
+// nni_tls_http_verified returns true if the peer has been verified using TLS.
+extern bool nni_http_tls_verified(nni_http_conn *);
+
+// nni_http_server will look for an existing server with the same
+// name and port, or create one if one does not exist. The servers
+// are reference counted to permit sharing the server object across
+// multiple subsystems. The URL hostname matching is very limited,
+// and the names must match *exactly* (without DNS resolution). Unless
+// a restricted binding is required, we recommend using a URL consisting
+// of an empty host name, such as http:// or https:// -- this would
+// convert to binding to the default port on all interfaces on the host.
+extern int nni_http_server_init(nni_http_server **, const nni_url *);
+
+// nni_http_server_fini drops the reference count on the server, and
+// if this was the last reference, closes down the server and frees
+// all related resources. It will not affect hijacked connections.
+extern void nni_http_server_fini(nni_http_server *);
+
+// nni_http_server_add_handler registers a handler on the server.
+// This function will return NNG_EADDRINUSE if a conflicting handler
+// is already registered (i.e. a handler with the same value for Host,
+// Method, and URL.)
+extern int nni_http_server_add_handler(nni_http_server *, nni_http_handler *);
+
+// nni_http_del_handler removes the given handler. The caller is
+// responsible for finalizing it afterwards. If the handler was not found
+// (not registered), NNG_ENOENT is returned. In this case it is unsafe
+// to make assumptions about the validity of the handler.
+extern int nni_http_server_del_handler(nni_http_server *, nni_http_handler *);
+
+// nni_http_server_set_tls adds a TLS configuration to the server,
+// and enables the use of it. This returns NNG_EBUSY if the server is
+// already started. This wipes out the entire TLS configuration on the
+// server client, so the caller must have configured it reasonably.
+// This API is not recommended unless the caller needs complete control
+// over the TLS configuration.
+extern int nni_http_server_set_tls(nni_http_server *, nng_tls_config *);
+
+// nni_http_server_get_tls obtains the TLS configuration if one is present,
+// or returns NNG_EINVAL. The TLS configuration is invalidated if the
+// nni_http_server_set_tls function is called, so be careful.
+extern int nni_http_server_get_tls(nni_http_server *, nng_tls_config **);
+
+// nni_http_server_start starts listening on the supplied port.
+extern int nni_http_server_start(nni_http_server *);
+
+// nni_http_server_stop stops the server, closing the listening socket.
+// Connections that have been "upgraded" are unaffected. Connections
+// associated with a callback will complete their callback, and then close.
+extern void nni_http_server_stop(nni_http_server *);
+
+// nni_http_hijack is intended to be called by a handler that wishes to
+// take over the processing of the HTTP session -- usually to change protocols
+// (such as in the case of websocket). The caller is responsible for obtaining
+// and disposal of the associated nni_http session. Also, this completely
+// disassociates the http session from the server, so the server may be
+// stopped or destroyed without affecting the hijacked session. Note also
+// that the hijacker will need to issue any HTTP reply itself. Finally,
+// when a session is hijacked, the caller is also responsible for disposing
+// of the request structure. (Some hijackers may keep the request for
+// further processing.)
+extern int nni_http_hijack(nni_http_conn *);
+
+// nni_http_handler_init creates a server handler object, for the supplied
+// URI (path only) with the callback.
+//
+// Note that methods which modify a handler cannot be called while the handler
+// is registered with the server, and that a handler can only be registered
+// once per server.
+//
+// The callback function will receive the following arguments (via
+// nng_aio_get_input(): nni_http_request *, nni_http_handler *, and
+// nni_http_context_t *. The first is a request object, for convenience.
+// The second is the handler, from which the callback can obtain any other
+// data it has set. The final is the http context, from which its possible
+// to hijack the session.
+extern int nni_http_handler_init(
+ nni_http_handler **, const char *, void (*)(nni_aio *));
+
+// nni_http_handler_init_file creates a handler with a function to serve
+// up a file named in the last argument.
+extern int nni_http_handler_init_file(
+ nni_http_handler **, const char *, const char *);
+
+// nni_http_handler_init_file_ctype is like nni_http_handler_init_file, but
+// provides for setting the Content-Type explicitly (last argument).
+extern int nni_http_handler_init_file_ctype(
+ nni_http_handler **, const char *, const char *, const char *);
+
+// nni_http_handler_init_directory arranges to serve up an entire
+// directory tree. The content types are determined from the built-in
+// content type list. Actual directories are required to contain a
+// file called index.html or index.htm. We do not generate directory
+// listings for security reasons.
+extern int nni_http_handler_init_directory(
+ nni_http_handler **, const char *, const char *);
+
+// nni_http_handler_init_static creates a handler that serves up static content
+// supplied, with the Content-Type supplied in the final argument.
+extern int nni_http_handler_init_static(
+ nni_http_handler **, const char *, const void *, size_t, const char *);
+
+// nni_http_handler_fini destroys a handler. This should only be done before
+// the handler is added, or after it is deleted. The server automatically
+// calls this for any handlers still registered with it if it is destroyed.
+extern void nni_http_handler_fini(nni_http_handler *);
+
+// nni_http_handler_set_tree marks the handler as servicing the entire
+// tree (e.g. a directory), rather than just a leaf node. The handler
+// will probably need to inspect the URL of the request.
+extern int nni_http_handler_set_tree(nni_http_handler *);
+
+// nni_http_handler_set_host limits the handler to only being called for
+// the given Host: field. This can be used to set up multiple virtual
+// hosts. Note that host names must match exactly. If NULL or an empty
+// string is specified, then the client's Host: field is ignored. (The
+// supplied value for the Host is copied by this function.) When supplying
+// a hostname, do not include a value for the port number; we do not match
+// on port number as we assume that clients MUST have gotten that part right
+// as we do not support virtual hosting on multiple separate ports; the
+// server only listens on a single port.
+extern int nni_http_handler_set_host(nni_http_handler *, const char *);
+
+// nni_http_handler_set_method limits the handler to only being called
+// for the given HTTP method. By default a handler is called for GET
+// methods only (and HEAD, which is handled internally.) Handlers can
+// be specified for any valid HTTP method. A handler may set the value
+// NULL here, to be called for any HTTP method. In such a case, the handler
+// is obligated to inspect the method. (Note: the passed method must be
+// in upper case and should come from a statically allocated string; the
+// server does not make its own copy.)
+extern int nni_http_handler_set_method(nni_http_handler *, const char *);
+
+// nni_http_handler_set_data sets an opaque data element on the handler,
+// which will be available to the callback via nni_http_handler_get_data.
+// The callback is an optional destructor, and will be called with the
+// data as its argument, when the handler is being destroyed.
+extern int nni_http_handler_set_data(nni_http_handler *, void *, nni_cb);
+
+// nni_http_handler_get_data returns the data that was previously stored
+// at that index. It returns NULL if no data was set, or an invalid index
+// is supplied.
+extern void *nni_http_handler_get_data(nni_http_handler *);
+
+// nni_http_handler_get_uri returns the URI set on the handler.
+extern const char *nni_http_handler_get_uri(nni_http_handler *);
+
+// Client stuff.
+
+extern int nni_http_client_init(nni_http_client **, const nni_url *);
+extern void nni_http_client_fini(nni_http_client *);
+
+// nni_http_client_set_tls sets the TLS configuration. This wipes out
+// the entire TLS configuration on the client, so the caller must have
+// configured it reasonably. This API is not recommended unless the
+// caller needs complete control over the TLS configuration.
+extern int nni_http_client_set_tls(nni_http_client *, nng_tls_config *);
+
+// nni_http_client_get_tls obtains the TLS configuration if one is present,
+// or returns NNG_EINVAL. The supplied TLS configuration object may
+// be invalidated by any future calls to nni_http_client_set_tls.
+extern int nni_http_client_get_tls(nni_http_client *, nng_tls_config **);
+
+extern void nni_http_client_connect(nni_http_client *, nni_aio *);
+
+#endif // NNG_SUPPLEMENTAL_HTTP_HTTP_API_H
diff --git a/src/supplemental/http/http_client.c b/src/supplemental/http/http_client.c
index 5cab15c9..484a2e72 100644
--- a/src/supplemental/http/http_client.c
+++ b/src/supplemental/http/http_client.c
@@ -16,7 +16,7 @@
#include "core/nng_impl.h"
#include "supplemental/tls/tls.h"
-#include "http.h"
+#include "http_api.h"
struct nng_http_client {
nni_list aios;
diff --git a/src/supplemental/http/http_conn.c b/src/supplemental/http/http_conn.c
index 525bd6b5..cdfdbaa9 100644
--- a/src/supplemental/http/http_conn.c
+++ b/src/supplemental/http/http_conn.c
@@ -14,7 +14,7 @@
#include "core/nng_impl.h"
#include "supplemental/tls/tls.h"
-#include "http.h"
+#include "http_api.h"
// We insist that individual headers fit in 8K.
// If you need more than that, you need something we can't do.
diff --git a/src/supplemental/http/http_msg.c b/src/supplemental/http/http_msg.c
index 9a5bac68..d4744471 100644
--- a/src/supplemental/http/http_msg.c
+++ b/src/supplemental/http/http_msg.c
@@ -15,7 +15,7 @@
#include <string.h>
#include "core/nng_impl.h"
-#include "http.h"
+#include "http_api.h"
// Note that as we parse headers, the rule is that if a header is already
// present, then we can append it to the existing header, separated by
diff --git a/src/supplemental/http/http_public.c b/src/supplemental/http/http_public.c
index 5437a000..b2007469 100644
--- a/src/supplemental/http/http_public.c
+++ b/src/supplemental/http/http_public.c
@@ -10,6 +10,7 @@
#include "core/nng_impl.h"
#include "http.h"
+#include "http_api.h"
// Symbols in this file are "public" versions of the HTTP API.
// These are suitable for exposure to applications.
diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c
index 69774bd5..f8b8c64b 100644
--- a/src/supplemental/http/http_server.c
+++ b/src/supplemental/http/http_server.c
@@ -16,7 +16,7 @@
#include "core/nng_impl.h"
#include "supplemental/tls/tls.h"
-#include "http.h"
+#include "http_api.h"
static int http_server_sys_init(void);
static void http_server_sys_fini(void);
diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c
index cf3fa8dc..d66d4fda 100644
--- a/src/supplemental/websocket/websocket.c
+++ b/src/supplemental/websocket/websocket.c
@@ -14,7 +14,7 @@
#include "core/nng_impl.h"
#include "supplemental/base64/base64.h"
-#include "supplemental/http/http.h"
+#include "supplemental/http/http_api.h"
#include "supplemental/sha1/sha1.h"
#include "websocket.h"
diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c
index 07300a6d..191f44fb 100644
--- a/src/transport/ws/websocket.c
+++ b/src/transport/ws/websocket.c
@@ -14,7 +14,7 @@
#include <string.h>
#include "core/nng_impl.h"
-#include "supplemental/http/http.h"
+#include "supplemental/http/http_api.h"
#include "supplemental/tls/tls.h"
#include "supplemental/websocket/websocket.h"
diff --git a/tests/httpclient.c b/tests/httpclient.c
index 2438ab4c..7a38ed8d 100644
--- a/tests/httpclient.c
+++ b/tests/httpclient.c
@@ -17,6 +17,7 @@
// Basic HTTP client tests.
#include "core/nng_impl.h"
+#include "supplemental/http/http.h"
#include "supplemental/sha1/sha1.h"
const uint8_t utf8_sha1sum[20] = { 0x54, 0xf3, 0xb8, 0xbb, 0xfe, 0xda, 0x6f,
diff --git a/tests/httpserver.c b/tests/httpserver.c
index e3d7ab25..e24c081f 100644
--- a/tests/httpserver.c
+++ b/tests/httpserver.c
@@ -17,6 +17,7 @@
// Basic HTTP server tests.
#include "core/nng_impl.h"
+#include "supplemental/http/http.h"
const char *doc1 = "<html><body>Someone <b>is</b> home!</body</html>";
const char *doc2 = "This is a text file.";