[][src]Crate async_http_proxy

async-http-proxy is a lightweight asynchronous HTTP proxy client library, which can be used to connect a to a TCP port via HTTP Connect proxy. It can use Tokio and async-std as asynchronous runtime.

Example

The following example shows how to connect to github.com via Connect proxy (tokio):

use async_http_proxy::http_connect_tokio;
use std::error::Error;
use tokio::net::TcpStream;
use url::Url;
// Features "runtime-tokio" and "basic-auth" have to be activated
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let mut stream = TcpStream::connect("127.0.0.1:8080").await?;
    let url = Url::parse("https://github.com")?;

    http_connect_tokio(&mut stream, &url).await?;
    // stream is now connect to github.com
    Ok(())
}

The following example shows how to connect to example.org with Basic Authentication via Connect proxy (async-std):

use async_http_proxy::http_connect_async_std;
use async_std::net::TcpStream;
use async_std::task;
use std::error::Error;
use url::Url;
// Features "async-std-tokio" and "basic-auth" have to be activated
fn main() -> Result<(), Box<dyn Error>> {
    task::block_on(async {
        let mut stream = TcpStream::connect("127.0.0.1:8080").await?;
        // feature "basic-auth" have to be active
        let url = Url::parse("https://USER:PASSWORD@example.org")?;

        http_connect_async_std(&mut stream, &url).await?;
        // stream is now connect to github.com
        Ok(())
    })
}

Enums

HttpError

This enum contains all errors, which can occur during the HTTP CONNECT.

Constants

MAXIMUM_RESPONSE_HEADERS

The maximum HTTP Headers, which can be parsed.

MAXIMUM_RESPONSE_HEADER_LENGTH

The maximum length of the response header.

Functions

http_connect_async_stdruntime-async-std

Connect to the server defined by the URL and check if the connection was established.

http_connect_tokioruntime-tokio

Connect to the server defined by the URL and check if the connection was established.