zeloxy 0.5.2

A library for creating lightweight, async, and lag-free proxy connections.
Documentation
# Zeloxy

[Russian Documentation]https://codeberg.org/nullclyze/zeloxy/src/branch/main/docs/RU.md | [English Documentation]https://codeberg.org/nullclyze/zeloxy/src/branch/main/docs/EN.md | [Examples]https://codeberg.org/nullclyze/zeloxy/src/branch/main/examples | [License]https://codeberg.org/nullclyze/zeloxy/src/branch/main/LICENSE

A Rust library for working with various proxies.

Supported proxy protocols:

- **HTTP**
  - Without auth
  - [Basic]https://datatracker.ietf.org/doc/html/rfc7235 auth
  - [Bearer]https://datatracker.ietf.org/doc/html/rfc6750 auth
- **HTTPS**
  - Without auth
  - [Basic]https://datatracker.ietf.org/doc/html/rfc7235 auth
  - [Bearer]https://datatracker.ietf.org/doc/html/rfc6750 auth
- **SOCKS5**
  - Without auth
  - [UserPass]https://datatracker.ietf.org/doc/html/rfc1929 auth
- **SOCKS4**
  - Without auth
  - [Ident]https://datatracker.ietf.org/doc/html/rfc1413 auth

# Focusing

- **Lightweight:** This crate does not use unnecessary dependencies and useless functionality.
- **Simplicity:** This crate contains clear and logical functionality with examples.
- **Built-in:** This crate offers built-in tools for convenient proxy management.
- **Asynchrony:** This crate is based on an asynchronous environment.
- **Lag-free:** This crate limits almost all operations with timeouts to prevent lags / freezes.

# Tasks and Goals

- [x] SOCKS4 proxy implementation
- [x] SOCKS5 proxy implementation
- [x] HTTP proxy implementation
- [x] HTTPS proxy implementation
- [ ] Trojan proxy implementation
- [x] Basic authorization support
- [x] Bearer authorization support
- [x] UserPass authorization support
- [ ] GSS-API authorization support
- [x] Ident authorization support
- [x] Proxy chain implementation
- [x] Automatic reordering of proxy chain on error
- [x] Built-in proxy stream
- [ ] Proxy scraper
- [x] Proxy lookup
- [x] Proxy ping
- [ ] Proxy stealth check

# Include

In `Cargo.toml`:

```toml
[dependencies]
zeloxy = { version = "0.5.2", features = ["all"] }
```

Information about available features: [read](https://codeberg.org/nullclyze/zeloxy/src/branch/main/docs/EN.md#library-features)

# Examples

Current examples can be found here: [browse](https://codeberg.org/nullclyze/zeloxy/src/branch/main/examples)

## Create a HTTP proxy stream

```rust
use zeloxy::important::{Proxy, ProxyResult, ProxyStream, ProxyProtocol};

#[tokio::main]
async fn main() -> ProxyResult<()> {
  // Создаём HTTP-прокси (в данном примере используется публичный прокси)
  let proxy = Proxy::new("91.132.92.231:80", ProxyProtocol::Http);

  // Создаём поток с прокси
  let stream = ProxyStream::new(proxy);

  // Подключаемся к целевому серверу
  stream.connect("example.com", 80).await?;

  // Отправляем GET-запрос на example.com
  let buf = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n".as_bytes();
  stream.write(buf).await?;

  // Читаем ответ и логгируем его
  let mut resp = Vec::new();
  stream.read_to_end(&mut resp).await?;
  println!("Ответ от example.com: {}", String::from_utf8_lossy(&resp));

  Ok(())
}
```

## Connect to SOCKS5 proxy

```rust
use zeloxy::important::Proxy;

#[tokio::main]
async fn main() {
  // Создаём SOCKS5-прокси (в данном примере используется публичный прокси)
  let proxy = Proxy::from("socks5://212.58.132.5:1080");

  // Подключаемся к прокси и логгируем результат
  match proxy.connect("ipinfo.io", 80).await {
    Ok(_) => {
      println!("Подключение установлено");
    }
    Err(e) => {
      println!("Ошибка подключения: {:?}", e);
    }
  }
}
```

## Create a proxy chain

```rust
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use zeloxy::create_chain;
use zeloxy::important::{Proxy, ProxyChain, ProxyResult};

#[tokio::main]
async fn main() -> ProxyResult<()> {
  // Создаём цепочку прокси
  let mut chain = create_chain![
    "socks4://98.181.137.83:4145",
    "socks4://98.170.57.249:4145",
    "socks5://212.58.132.5:1080",
  ];

  // Подключаемся к целевому серверу через цепочку
  let mut stream = chain.connect("ipinfo.io", 80, false).await?;

  // Отправляем GET-запрос
  stream.write_all(b"GET / HTTP/1.0\r\nHost: ipinfo.io\r\n\r\n").await?;

  // Читаем ответ (в данном случае информация об IP)
  let mut resp = Vec::new();
  stream.read_to_end(&mut resp).await?;

  // Логгируем выходной IP (здесь должно быть { "ip": "212.58.132.5:1080" })
  println!("Выход: {}", String::from_utf8_lossy(&resp));

  Ok(())
}
```