Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http no tree exclusive #2079

Merged
merged 3 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions docs/man/nng_http_handler_alloc.3http.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ The `Content-Type` will be set automatically based upon the extension
of the requested file name. If a content type cannot be determined from
the extension, then `application/octet-stream` is used.

The directory handler is created as a tree handler initially in exclusive mode (see
xref:nng_http_handler_set_tree.3http.adoc[nng_http_handler_set_tree_exclusive]).
This can be changed by calling
xref:nng_http_handler_set_tree.3http.adoc[nng_http_handler_set_tree(3http)]
after creating the directory handler.
The directory handler is created as a tree handler.

=== File Handler

Expand Down Expand Up @@ -183,7 +179,6 @@ xref:nng_http_handler_free.3http.adoc[nng_http_handler_free(3http)],
xref:nng_http_handler_set_host.3http.adoc[nng_http_handler_set_host(3http)],
xref:nng_http_handler_set_method.3http.adoc[nng_http_handler_set_method(3http)],
xref:nng_http_handler_set_tree.3http.adoc[nng_http_handler_set_tree(3http)],
xref:nng_http_handler_set_tree.3http.adoc[nng_http_handler_set_tree_exclusive(3http)],
xref:nng_http_server_add_handler.3http.adoc[nng_http_server_add_handler(3http)],
xref:nng_strerror.3.adoc[nng_strerror(3)],
xref:nng_aio.5.adoc[nng_aio(5)],
Expand Down
20 changes: 4 additions & 16 deletions docs/man/nng_http_handler_set_tree.3http.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= nng_http_handler_set_tree(3http)

// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
// Copyright 2020 Dirac Research <[email protected]>
//
Expand All @@ -21,8 +21,6 @@ nng_http_handler_set_tree - set HTTP handler to match trees
#include <nng/http.h>

void nng_http_handler_set_tree(nng_http_handler *handler);

void nng_http_handler_set_tree_exclusive(nng_http_handler *handler);
----

== DESCRIPTION
Expand All @@ -31,27 +29,17 @@ The `nng_http_handler_set_tree()` function causes the _handler_ to be matched if
by the client is a logical child of the path for _handler_, and no more specific
_handler_ has been registered.

The `nng_http_handler_set_tree_exclusive()` function is similar to `nng_http_server_set_tree()`
with the distinction that the _handler_ will be considered to *exclusively* handle its request URI.
Unlike `nng_http_server_set_tree()`, it will not be possible to register additional
handlers in logical subdirectories of _handler_.

This is useful in cases when the handler would like to examine the entire path
and possibly behave differently; for example a REST API that uses the rest of
the path to pass additional parameters.

TIP: These methods are useful when constructing API handlers where a single
TIP: This function is useful when constructing API handlers where a single
service address (path) supports dynamically generated children.

TIP: The non-exclusive form is also useful for providing a default handler to be
generated when a more specific child does not exist.
This can provide a better experience for users than the standard 404 error
handling.
It can also provide a logical fallback instead of relying on a 404 error code.

== SEE ALSO

[.text-left]
xref:nng_http_handler_alloc.3http.adoc[nng_http_handler_alloc(3http)],
xref:nng_http_server_add_handler.3http.adoc[nng_http_server_add_handler(3http)],
xref:nng_http_get_method.3http.adoc[nng_http_get_method(3http)],
xref:nng.7.adoc[nng(7)]
xref:nng_http_get_method.3http.adoc[nng_http_get_method(3http)]
44 changes: 0 additions & 44 deletions docs/man/nng_http_set_method.3http.adoc

This file was deleted.

54 changes: 0 additions & 54 deletions docs/man/nng_http_set_reason.3http.adoc

This file was deleted.

1 change: 0 additions & 1 deletion docs/ref/migrate/nng1.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ They may silently truncate data.
- [`nng_http_handler_set_host`]
- [`nng_http_handler_set_method`]
- [`nng_http_handler_set_tree`]
- [`nng_http_handler_set_tree_exclusive`]

The HTTP handler objects may not be modified once in use. Previously this would fail with `NNG_EBUSY`.
These checks are removed now, but debug builds will assert if an application tries to do so.
Expand Down
8 changes: 0 additions & 8 deletions include/nng/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,6 @@ NNG_DECL void nng_http_handler_collect_body(nng_http_handler *, bool, size_t);
// called for an exact path match.
NNG_DECL void nng_http_handler_set_tree(nng_http_handler *);

// nng_http_handler_set_tree_exclusive indicates that the handler is being
// registered for a heirarchical tree *exclusively*, 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. Exclusive means that any
// other handler on a conflicting path will induce an address conflict error
// when added to a server.
NNG_DECL void nng_http_handler_set_tree_exclusive(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 de-allocator and
// will be called with the supplied data as an argument, when the handler
Expand Down
7 changes: 0 additions & 7 deletions src/supplemental/http/http_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,6 @@ extern void nni_http_handler_collect_body(nni_http_handler *, bool, size_t);
// will probably need to inspect the URL of the request.
extern void nni_http_handler_set_tree(nni_http_handler *);

// nni_http_handler_set_tree_exclusive marks the handler as servicing the
// entire tree (e.g. a directory) exclusively, rather than just a leaf node.
// When servicing a tree exclusively, other handlers sharing parts of the uri
// will induce an address conflict when adding them to a server. The handler
// will probably need to inspect the URL of the request.
extern void nni_http_handler_set_tree_exclusive(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
Expand Down
33 changes: 0 additions & 33 deletions src/supplemental/http/http_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,6 @@ nni_http_res_reset(nni_http_res *res)
res->code = 0;
}

static int
http_del_header(nni_list *hdrs, const char *key)
{
http_header *h;
NNI_LIST_FOREACH (hdrs, h) {
if (nni_strcasecmp(key, h->name) == 0) {
nni_http_free_header(h);
return (0);
}
}
return (NNG_ENOENT);
}

int
nni_http_req_del_header(nni_http_req *req, const char *key)
{
int rv = NNG_ENOENT;
while (http_del_header(&req->data.hdrs, key) == 0) {
rv = 0;
}
return (rv);
}

int
nni_http_res_del_header(nni_http_res *res, const char *key)
{
int rv = NNG_ENOENT;
while (http_del_header(&res->data.hdrs, key) == 0) {
rv = 0;
}
return (rv);
}

// http_entity_set_data sets the entity, but does not update the
// content-length header.
static void
Expand Down
10 changes: 0 additions & 10 deletions src/supplemental/http/http_public.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,6 @@ nng_http_handler_set_tree(nng_http_handler *h)
#endif
}

void
nng_http_handler_set_tree_exclusive(nng_http_handler *h)
{
#ifdef NNG_SUPP_HTTP
nni_http_handler_set_tree_exclusive(h);
#else
NNI_ARG_UNUSED(h);
#endif
}

void
nng_http_handler_set_data(nng_http_handler *h, void *dat, void (*dtor)(void *))
{
Expand Down
Loading
Loading