def start_response(status, headers): resp = HttpResponse() resp.status = status [resp.header(h).values.append(v) for h, v in headers] return reject(resp)
def on_message_complete(self, is_chunked, keep_alive): callback = self._upstream.close self._upstream.handle.disable_reading() if keep_alive: self._http_msg = HttpResponse() callback = self._downstream.handle.resume_reading if self._intercepted: # Serialize our message to them self._downstream.write(self._http_msg.to_bytes(), callback) elif is_chunked or self._chunked: # Finish the last chunk. self._downstream.write(_CHUNK_CLOSE, callback) else: callback()
request_func._handles_response_body = True return request_func class HttpFilter(object): """ HttpFilter is a marker class that may be utilized for dynamic gathering of filter logic. """ pass """ Default return object. This should be configurable. """ _DEFAULT_REJECT_RESP = HttpResponse() _DEFAULT_REJECT_RESP.version = b'1.1' _DEFAULT_REJECT_RESP.status = '400 Bad Request' _DEFAULT_REJECT_RESP.header('Content-Length').values.append('0') """ Default filter action singletons. """ _DEFAULT_PASS_ACTION = FilterAction(NEXT_FILTER) _DEFAULT_CONSUME_ACTION = FilterAction(CONSUME) def consume(): """ Consumes the event and does not allow any further downstream filters to see it. This effectively halts execution of the filter chain but leaves the request to pass through the proxy.
def __init__(self, downstream, upstream, filter_pl, request): super(UpstreamHandler, self).__init__(filter_pl, HttpResponse()) self._downstream = downstream self._upstream = upstream self._request = request
ResponseParser, ParserDelegate) import traceback _LOG = get_logger(__name__) """ String representing a 0 length HTTP chunked encoding chunk. """ _CHUNK_CLOSE = b'0\r\n\r\n' """ Default return object on error. This should be configurable. """ _BAD_GATEWAY_RESP = HttpResponse() _BAD_GATEWAY_RESP.version = b'1.1' _BAD_GATEWAY_RESP.status = '502 Bad Gateway' _BAD_GATEWAY_RESP.header('Server').values.append('pyrox/{}'.format(VERSION)) _BAD_GATEWAY_RESP.header('Content-Length').values.append('0') """ Default return object on no route or upstream not responding. This should be configurable. """ _UPSTREAM_UNAVAILABLE = HttpResponse() _UPSTREAM_UNAVAILABLE.version = b'1.1' _UPSTREAM_UNAVAILABLE.status = '503 Service Unavailable' _UPSTREAM_UNAVAILABLE.header('Server').values.append('pyrox/{}'.format(VERSION)) _UPSTREAM_UNAVAILABLE.header('Content-Length').values.append('0')