10. Cross-Protocol Proxying between CoAP and HTTP
CoAP supports a limited subset of HTTP functionality, thus cross-protocol proxying to HTTP is straightforward. There may be several reasons for proxying between CoAP and HTTP, for example when designing a web interface that is accessible from both protocols, or when implementing a CoAP-HTTP proxy.
10.1. CoAP-HTTP Proxying
If a request contains the Proxy-Uri or Proxy-Scheme Option with an 'http' or 'https' URI [RFC2616], then the receiving CoAP endpoint (called "the proxy" in the following) is requested to perform the operation specified by the request method on the HTTP resource identified in the HTTP URI, and return the result to the client.
The proxy processes the request as follows:
- The CoAP method is mapped to the HTTP method
- CoAP options are mapped to HTTP headers
- The request is forwarded to the HTTP server
- The HTTP response is received and processed
- HTTP headers and status codes are mapped back to CoAP options and response codes
- The response is sent back to the CoAP client
10.2. HTTP-CoAP Proxying
If the Request-URI of an HTTP request contains a "coap" or "coaps" URI, then the receiving HTTP endpoint (called "the proxy" in the following) is requested to perform the operation specified by the request method on the CoAP resource identified by the URI, and return the result to the client.
The mapping process is the reverse of CoAP-HTTP proxying:
- The HTTP method is mapped to the CoAP method
- HTTP headers are mapped to CoAP options
- The request is forwarded to the CoAP server
- The CoAP response is received and processed
- CoAP options and response codes are mapped back to HTTP headers and status codes
- The response is sent back to the HTTP client
For detailed mapping rules and considerations, please refer to the official RFC 7252 document and related specifications such as [RFC8075] for CoAP-HTTP mapping guidelines.