def test_wsgi_environ(path=None, method=None, headers=None, extra=None, secure=False, loop=None, body=None): '''An function to create a WSGI environment dictionary for testing. :param url: the resource in the ``PATH_INFO``. :param method: the ``REQUEST_METHOD``. :param headers: optional request headers :params secure: a secure connection? :param extra: additional dictionary of parameters to add. :return: a valid WSGI environ dictionary. ''' parser = http_parser(kind=0) method = (method or 'GET').upper() path = iri_to_uri(path or '/') request_headers = Headers(headers, kind='client') # Add Host if not available parsed = urlparse(path) if 'host' not in request_headers: if not parsed.netloc: path = '%s%s' % ('https://:443' if secure else 'http://:80', path) else: request_headers['host'] = parsed.netloc # data = '%s %s HTTP/1.1\r\n\r\n' % (method, path) data = data.encode('latin1') parser.execute(data, len(data)) # stream = io.BytesIO(body or b'') return wsgi_environ(stream, parser, request_headers, ('127.0.0.1', 8060), '255.0.1.2:8080', Headers(), https=secure, extra=extra)
def test_wsgi_environ(path=None, method=None, headers=None, extra=None, secure=False, loop=None, body=None): '''An function to create a WSGI environment dictionary for testing. :param url: the resource in the ``PATH_INFO``. :param method: the ``REQUEST_METHOD``. :param headers: optional request headers :params secure: a secure connection? :param extra: additional dictionary of parameters to add. :return: a valid WSGI environ dictionary. ''' parser = http_parser(kind=0) method = (method or 'GET').upper() path = iri_to_uri(path or '/') request_headers = Headers(headers, kind='client') # Add Host if not available parsed = urlparse(path) if 'host' not in request_headers: if not parsed.netloc: scheme = ('https' if secure else 'http') path = '%s://127.0.0.1%s' % (scheme, path) else: request_headers['host'] = parsed.netloc # data = '%s %s HTTP/1.1\r\n\r\n' % (method, path) data = data.encode('latin1') parser.execute(data, len(data)) # stream = io.BytesIO(body or b'') return wsgi_environ(stream, parser, request_headers, ('127.0.0.1', 8060), '255.0.1.2:8080', Headers(), https=secure, extra=extra)
def test_wsgi_environ(path='/', method=None, headers=None, extra=None, secure=False, loop=None): '''An function to create a WSGI environment dictionary for testing. :param url: the resource in the ``PATH_INFO``. :param method: the ``REQUEST_METHOD``. :param headers: optional request headers :params secure: a secure connection? :param extra: additional dictionary of parameters to add. :return: a valid WSGI environ dictionary. ''' parser = http_parser(kind=0) method = (method or 'GET').upper() path = iri_to_uri(path) data = '%s %s HTTP/1.1\r\n\r\n' % (method, path) data = data.encode('latin1') parser.execute(data, len(data)) request_headers = Headers(headers, kind='client') # Add Host if not available parsed = urlparse(path) if parsed.netloc and 'host' not in request_headers: request_headers['host'] = parsed.netloc # headers = Headers() stream = StreamReader(request_headers, parser) extra = extra or {} extra['pulsar.connection'] = FakeConnection(loop=loop) return wsgi_environ(stream, ('127.0.0.1', 8060), '777.777.777.777:8080', headers, https=secure, extra=extra)
def test_wsgi_environ(path=None, method=None, headers=None, extra=None, secure=False, loop=None, body=None): """An function to create a WSGI environment dictionary for testing. :param url: the resource in the ``PATH_INFO``. :param method: the ``REQUEST_METHOD``. :param headers: optional request headers :params secure: a secure connection? :param extra: additional dictionary of parameters to add. :return: a valid WSGI environ dictionary. """ parser = http_parser(kind=0) method = (method or "GET").upper() path = iri_to_uri(path or "/") request_headers = Headers(headers, kind="client") # Add Host if not available parsed = urlparse(path) if "host" not in request_headers: if not parsed.netloc: path = "%s%s" % ("https://:443" if secure else "http://:80", path) else: request_headers["host"] = parsed.netloc # data = "%s %s HTTP/1.1\r\n\r\n" % (method, path) data = data.encode("latin1") parser.execute(data, len(data)) # stream = io.BytesIO(body or b"") return wsgi_environ( stream, parser, request_headers, ("127.0.0.1", 8060), "255.0.1.2:8080", Headers(), https=secure, extra=extra )
def test_wsgi_environ(url='/', method=None, headers=None, extra=None, secure=False): '''An function to create a WSGI environment dictionary for testing. :param url: the resource in the ``PATH_INFO``. :param method: the ``REQUEST_METHOD``. :param headers: optional request headers :params secure: a secure connection? :param extra: additional dictionary of parameters to add. :return: a valid WSGI environ dictionary. ''' parser = http_parser(kind=0) method = (method or 'GET').upper() data = '%s %s HTTP/1.1\r\n\r\n' % (method, url) data = data.encode('utf-8') parser.execute(data, len(data)) request_headers = Headers(headers, kind='client') headers = Headers() stream = StreamReader(request_headers, parser) return wsgi_environ(stream, ('127.0.0.1', 8060), '777.777.777.777:8080', request_headers, headers, https=secure, extra=extra)
def test_wsgi_environ(path=None, method=None, headers=None, extra=None, secure=False, loop=None, body=None): '''An function to create a WSGI environment dictionary for testing. :param url: the resource in the ``PATH_INFO``. :param method: the ``REQUEST_METHOD``. :param headers: optional request headers :params secure: a secure connection? :param extra: additional dictionary of parameters to add. :return: a valid WSGI environ dictionary. ''' parser = http_parser(kind=0) method = (method or 'GET').upper() path = iri_to_uri(path or '/') request_headers = Headers(headers, kind='client') # Add Host if not available parsed = urlparse(path) if 'host' not in request_headers: if not parsed.netloc: path = '%s%s' % ('https://:443' if secure else 'http://:80', path) else: request_headers['host'] = parsed.netloc # data = '%s %s HTTP/1.1\r\n\r\n' % (method, path) data = data.encode('latin1') parser.execute(data, len(data)) # headers = Headers() stream = StreamReader(request_headers, parser) stream.buffer = body or b'' stream.on_message_complete.set_result(None) extra = extra or {} return wsgi_environ(stream, ('127.0.0.1', 8060), '777.777.777.777:8080', headers, https=secure, extra=extra)
def __init__(self, wsgi_callable, cfg, server_software=None, loop=None): super(HttpServerResponse, self).__init__(loop=loop) self.wsgi_callable = wsgi_callable self.cfg = cfg self.parser = http_parser(kind=0) self.headers = Headers() self.keep_alive = False self.SERVER_SOFTWARE = server_software or self.SERVER_SOFTWARE
def __init__(self, wsgi_callable, cfg, server_software=None): super(HttpServerResponse, self).__init__() self.wsgi_callable = wsgi_callable self.cfg = cfg self.parser = http_parser(kind=0) self.headers = Headers() self.keep_alive = False self.SERVER_SOFTWARE = server_software or self.SERVER_SOFTWARE
def test_wsgi_environ(url='/', method=None, headers=None, extra=None, secure=False): '''An function to create a WSGI environment dictionary for testing. :param url: the resource in the ``PATH_INFO``. :param method: the ``REQUEST_METHOD``. :param headers: optional request headers :params secure: a secure connection? :param extra: additional dictionary of parameters to add. :return: a valid WSGI environ dictionary. ''' parser = http_parser(kind=0) method = (method or 'GET').upper() data = '%s %s HTTP/1.1\r\n\r\n' % (method, url) data = data.encode('utf-8') parser.execute(data, len(data)) request_headers = Headers(headers, kind='client') headers = Headers() stream = StreamReader(request_headers, parser) return wsgi_environ(stream, ('127.0.0.1', 8060), '777.777.777.777:8080', request_headers, headers, https=secure, extra=extra)
def current_consumer(self): consumer = http.HttpResponse(self._loop) consumer._connection = self consumer.server_side = None if self._producer.wsgi: server_side = HttpServerResponse( self._producer.wsgi, self._producer.test.cfg, loop=self._loop ) server_side._connection = DummyServerConnection( server_side, consumer, self.address ) consumer.server_side = server_side else: consumer.server_side = None consumer.message = b'' consumer.in_parser = http_parser(kind=0) consumer.connection_made(self) self._current_consumer = consumer return consumer
def current_consumer(self): consumer = http.HttpResponse(self._loop) consumer._connection = self consumer.server_side = None if self._producer.wsgi: server_side = HttpServerResponse( self._producer.wsgi, self._producer.test.cfg, loop=self._loop ) server_side._connection = DummyServerConnection( server_side, consumer, self.address ) consumer.server_side = server_side else: consumer.server_side = None consumer.message = b'' consumer.in_parser = http_parser(kind=0) consumer.connection_made(self) self._current_consumer = consumer return consumer