nopasaran.tools.http_1_socket_server.HTTP1SocketServer

class nopasaran.tools.http_1_socket_server.HTTP1SocketServer

Bases: object

A simple HTTP/1.1 server using sockets.

__init__()

Methods

__init__()

close()

Close the HTTP/1.1 connection and clean up resources

handle_client_connection(client_socket, timeout)

Handle a client connection by processing the incoming request and sending the appropriate response.

receive_test_frames()

Listen for HTTP/1.1 requests until a timeout occurs, then process all received requests.

start(host, port)

Start the HTTP/1.1 server to receive HTTP/1.1 requests.

wait_for_request(port, timeout)

Wait for an HTTP request or timeout.

close()

Close the HTTP/1.1 connection and clean up resources

handle_client_connection(client_socket, timeout)

Handle a client connection by processing the incoming request and sending the appropriate response.

receive_test_frames()

Listen for HTTP/1.1 requests until a timeout occurs, then process all received requests.

Returns:
Tuple[str, str, str]: (event_name, message, received_data)
  • event_name: The type of event that occurred (from EventNames)
    • TIMEOUT: Timeout occurred before all requests were received

    • REJECTED: Received a 4xx or 5xx status code

    • RECEIVED_REQUESTS: All requests have been received

    • ERROR: Error occurred while receiving requests

  • message: A descriptive message about what happened

  • received_data: String representation of the received requests or None

start(host, port)

Start the HTTP/1.1 server to receive HTTP/1.1 requests.

wait_for_request(port, timeout)

Wait for an HTTP request or timeout.

Args:

port (int): The port to run the server on. timeout (int): The timeout duration in seconds.

Returns:

Tuple[bytes or None, str]: The raw received request data or None if a timeout occurs, and the event name.