Crate socks_http_kit

Source
Expand description

A lightweight library for SOCKS5 and HTTP proxy protocol encoding and parsing, designed to facilitate complex proxy applications.

This library serves as a foundation layer for higher-level proxy protocols. It provides a set of Tokio-based asynchronous functions specifically for parsing and processing SOCKS5 and HTTP proxy protocol requests and responses. The library employs I/O-agnostic design, meaning it doesn’t spawn internal threads, establish network connections, or perform DNS resolution. Instead, it delegates these controls entirely to the user code, enabling flexible integration with various proxy applications.

Socks-Http-Kit supports:

  • SOCKS5 client and server implementations

    • Full support for CONNECT, BIND, and UDP_ASSOCIATE commands.
    • Username/password authentication mechanism.
  • HTTP proxy client and server implementations.

    • HTTP BASIC authentication support.

§SOCKS5

  • Use socks5_connect to send handshake to SOCKS5 servers, with optional authentication information.
  • Use socks5_accept to receive and parse handshake from SOCKS5 clients, returning the SOCKS5 command type and target address.
  • Use socks5_finalize_accept to send request processing results back to SOCKS5 clients, completing the handshake process.
  • socks5_read_udp_header parses SOCKS5 UDP protocol headers from UDP packet buffers.
  • socks5_write_udp_header writes SOCKS5 UDP protocol headers to specified buffers.

§HTTP

  • Use http_connect to send handshake to HTTP proxy servers, with optional authentication information.
  • Use http_accept to receive and parse handshake from HTTP clients, extracting target address information.
  • Use http_finalize_accept to send processing results back to HTTP clients, completing the proxy handshake process.

§Address

§Cargo Features

The library provides two optional features, both disabled by default:

  • socks5: Enables SOCKS5 proxy protocol functionality, including client and server communication, authentication, and UDP parsing and encoding functions.
  • http: Enables HTTP proxy protocol functionality.

Enums§

AddrError
Errors that can occur address decoding operations.
Address
Represents a network address in various supported formats.
AuthMethod
Authentication methods supported by the proxy protocol.
HttpErrorhttp
Errors that can occur during HTTP proxy protocol operations.
HttpReplyhttp
HTTP proxy response status codes as defined in RFC 7231.
Socks5Commandsocks5
SOCKS5 commands as defined in RFC 1928 section 4.
Socks5Errorsocks5
Errors that can occur during SOCKS5 protocol operations.
Socks5Replysocks5
SOCKS5 server reply codes as defined in RFC 1928 section 6.

Functions§

http_accepthttp
Accepts an HTTP proxy connection request from a client.
http_connecthttp
Establishes an HTTP proxy connection to a target server.
http_finalize_accepthttp
Completes an HTTP proxy connection by sending a response to the client.
socks5_acceptsocks5
Accepts a SOCKS5 proxy connection request from a client.
socks5_connectsocks5
Establishes a SOCKS5 proxy connection to a target server.
socks5_finalize_acceptsocks5
Completes a SOCKS5 proxy connection by sending a reply to the client.
socks5_read_udp_headersocks5
Reads and parses the SOCKS5 UDP header information and destination address from a UDP packet buffer.
socks5_write_udp_headersocks5
Writes the SOCKS5 UDP header and destination address into a buffer.