aiocoap.proxy.server module

Basic implementation of CoAP-CoAP proxying

This is work in progress and not yet part of the API.

exception aiocoap.proxy.server.CanNotRedirect(message=None)

Bases: aiocoap.error.ConstructionRenderableError

message = 'Proxy redirection failed'
exception aiocoap.proxy.server.NoUriSplitting(message=None)

Bases: aiocoap.proxy.server.CanNotRedirect

code = <Response Code 161 "5.01 Not Implemented">
message = 'URI splitting not implemented, please use Proxy-Scheme.'
exception aiocoap.proxy.server.IncompleteProxyUri(message=None)

Bases: aiocoap.proxy.server.CanNotRedirect

code = <Response Code 128 "4.00 Bad Request">
message = 'Proxying requires Proxy-Scheme and Uri-Host'
exception aiocoap.proxy.server.NotAForwardProxy(message=None)

Bases: aiocoap.proxy.server.CanNotRedirect

code = <Response Code 165 "5.05 Proxying Not Supported">
message = 'This is a reverse proxy, not a forward one.'
exception aiocoap.proxy.server.NoSuchHostname(message=None)

Bases: aiocoap.proxy.server.CanNotRedirect

code = <Response Code 132 "4.04 Not Found">
message = ''
exception aiocoap.proxy.server.CanNotRedirectBecauseOfUnsafeOptions(options)

Bases: aiocoap.proxy.server.CanNotRedirect

code = <Response Code 130 "4.02 Bad Option">
aiocoap.proxy.server.raise_unless_safe(request, known_options)

Raise a BAD_OPTION CanNotRedirect unless all options in request are safe to forward or known

class aiocoap.proxy.server.Proxy(outgoing_context, logger=None)

Bases: aiocoap.interfaces.Resource

interpret_block_options = False
add_redirector(redirector)
apply_redirection(request)
render_to_pipe(request: aiocoap.pipe.Pipe)

Create any number of responses (as indicated by the request) into the request stream.

This method is provided by the base Resource classes; if it is overridden, then render(), needs_blockwise_assembly() and ObservableResource.add_observation() are not used any more. (They still need to be implemented to comply with the interface definition, which is yet to be updated).

needs_blockwise_assembly(request)

Indicator to the protocol.Responder about whether it should assemble request blocks to a single request and extract the requested blocks from a complete-resource answer (True), or whether the resource will do that by itself (False).

render(request)

Return a message that can be sent back to the requester.

This does not need to set any low-level message options like remote, token or message type; it does however need to set a response code.

A response returned may carry a no_response option (which is actually specified to apply to requests only); the underlying transports will decide based on that and its code whether to actually transmit the response.

class aiocoap.proxy.server.ProxyWithPooledObservations(outgoing_context, logger=None)

Bases: aiocoap.proxy.server.Proxy, aiocoap.interfaces.ObservableResource

add_observation(request, serverobservation)

As ProxiedResource is intended to be just the proxy’s interface toward the Context, accepting observations is handled here, where the observations handling can be defined by the subclasses.

render(request)

Return a message that can be sent back to the requester.

This does not need to set any low-level message options like remote, token or message type; it does however need to set a response code.

A response returned may carry a no_response option (which is actually specified to apply to requests only); the underlying transports will decide based on that and its code whether to actually transmit the response.

class aiocoap.proxy.server.ForwardProxy(outgoing_context, logger=None)

Bases: aiocoap.proxy.server.Proxy

apply_redirection(request)
class aiocoap.proxy.server.ForwardProxyWithPooledObservations(outgoing_context, logger=None)

Bases: aiocoap.proxy.server.ForwardProxy, aiocoap.proxy.server.ProxyWithPooledObservations

class aiocoap.proxy.server.ReverseProxy(*args, **kwargs)

Bases: aiocoap.proxy.server.Proxy

class aiocoap.proxy.server.ReverseProxyWithPooledObservations(*args, **kwargs)

Bases: aiocoap.proxy.server.ReverseProxy, aiocoap.proxy.server.ProxyWithPooledObservations

class aiocoap.proxy.server.Redirector

Bases: object

apply_redirection(request)
class aiocoap.proxy.server.NameBasedVirtualHost(match_name, target, rewrite_uri_host=False, use_as_proxy=False)

Bases: aiocoap.proxy.server.Redirector

apply_redirection(request)
class aiocoap.proxy.server.SubdomainVirtualHost(*args, **kwargs)

Bases: aiocoap.proxy.server.NameBasedVirtualHost

class aiocoap.proxy.server.UnconditionalRedirector(target, use_as_proxy=False)

Bases: aiocoap.proxy.server.Redirector

apply_redirection(request)
class aiocoap.proxy.server.SubresourceVirtualHost(path, target)

Bases: aiocoap.proxy.server.Redirector

apply_redirection(request)