CoAP reverse-proxy for specific resources.
The CoAP specification (RFC 7252) section 5.7 defines:
- Forward-proxies: In which the client that issues a request specifies where it should be forwarded, using the Proxy-Uri option.
- Reverse-proxies: In which the server decides that a request for a given resource should be forwarded to another server, and acts as a middleman.
This file defines classes used for reverse-proxies, which build on the coap::Resource concept (
- See also
- coap_resource.h):
- coap::ProxyResource defines a CoAP resource whose requests should be forwarded to a CoAP server at a designated IP address and UDP port. The next-hop address can be configured separately for each resource.
- coap::ProxyServer defines a CoAP endpoint that can service a mixture of local and/or proxy Resource objects.
To forward a request, coap::ProxyServer uses two coap::Connection objects:
- The first Connection is to the client, opened by an incoming request.
- That event calls ResourceServer::coap_request(), which reads the URI-Path option to identify the matching coap::Resource or coap::ProxyResource.
- If the URI matches a coap::ProxyResource, then that object processes the get/post/put/delete request.
- See also
- ProxyResource::request_any.
- The
request_any callback opens (or reuses) a coap::Connection to the downstream server, then forwards the request contents. The outgoing message-ID is stored in both client and server objects.
- When a response is received, that triggers ProxyServer::coap_response(), which tries to match the response's message-ID against the ID stored in the previous step, to find the original client Connection object.
- If a match is found, ProxyServer::proxy_response forwards the response. Otherwise, it notifies a callback.
- See also
- ProxyServer::local_response.
TODO: Support caching, etags, and the PROXY_URI tag.
Definition in file coap_proxy.h.