45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
proxy.py
|
|
~~~~~~~~
|
|
⚡⚡⚡ Fast, Lightweight, Programmable Proxy Server in a single Python file.
|
|
|
|
:copyright: (c) 2013-present by Abhinav Singh and contributors.
|
|
:license: BSD, see LICENSE for more details.
|
|
"""
|
|
from proxy.proxy import TestCase
|
|
from proxy.common.constants import DEFAULT_CLIENT_RECVBUF_SIZE, PROXY_AGENT_HEADER_VALUE
|
|
from proxy.common.utils import socket_connection, build_http_request, build_http_response
|
|
from proxy.http.codes import httpStatusCodes
|
|
from proxy.http.methods import httpMethods
|
|
|
|
|
|
class TestProxyPyEmbedded(TestCase):
|
|
|
|
PROXY_PY_STARTUP_FLAGS = [
|
|
'--num-workers', '1',
|
|
'--enable-web-server',
|
|
]
|
|
|
|
def test_with_proxy(self) -> None:
|
|
"""Makes a HTTP request to in-build web server via proxy server"""
|
|
with socket_connection(('localhost', self.proxy_port)) as conn:
|
|
conn.send(
|
|
build_http_request(
|
|
httpMethods.GET, b'http://localhost:%d/' % self.proxy_port,
|
|
headers={
|
|
b'Host': b'localhost:%d' % self.proxy_port,
|
|
})
|
|
)
|
|
response = conn.recv(DEFAULT_CLIENT_RECVBUF_SIZE)
|
|
self.assertEqual(
|
|
response,
|
|
build_http_response(
|
|
httpStatusCodes.NOT_FOUND, reason=b'NOT FOUND',
|
|
headers={
|
|
b'Server': PROXY_AGENT_HEADER_VALUE,
|
|
b'Connection': b'close'
|
|
}
|
|
)
|
|
)
|