#server #socket #tcp

bin+lib rserver

Asynchronous TCP server for intercepting requests, modifying request headers, and replacing responses

7 releases

0.1.6 Dec 23, 2022
0.1.5 Dec 22, 2022
0.1.4 Aug 17, 2020

#106 in HTTP server

24 downloads per month

MIT license

356 lines


A asynchronous library/app for intercepting/sniffing TCP requests, modifying headers and responses.


To Install RServer, Please use the following command :

cargo install rserver


How to use the RServer to intercept/sniff TCP requests. RServer currently runs on 8080 port by default.

To run RServer, use the folowing command :


Please set the browser/system proxy as host and port 8080 (default port of RServer) to use Rserver for intercepting all requests.

If you directly want to test RServer installation without doing the above step, please run the below command :

https_proxy= curl https://www.google.com


rserver [OPTIONS]

    --help       Prints help information
-V, --version    Prints version information

    --enable-proxy <enable-proxy>    Enable proxy flag [default: false]
-h, --host <host>                    Server host [default:]
-p, --port <port>                    Server port [default: 8080]
    --proxy-host <proxy-host>        Proxy host
    --proxy-port <proxy-port>        Proxy port

To use rsever Rust library , please see the below example :

use rserver::Config;
use rserver::Server;

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = Config::default();
    let server = Server::new(config);


  • Asynchronous server.
  • Add HTTPS / CONNECT method support.
  • Minor bug fixes & other improvements.
  • Modular code

Internal API

How to read the stream data and return stream data & its length.

/// Read the stream data and return stream data & its length
fn read_stream(stream: &mut TcpStream) -> (Vec<u8>, usize) {
    let buffer_size = 512;
    let mut request_buffer = vec![];
    // let us loop & try to read the whole request data
    let mut request_len = 0usize;
    loop {
        let mut buffer = vec![0; buffer_size];
        match stream.read(&mut buffer) {
            Ok(n) => {
                if n == 0 {
                } else {
                    request_len += n;

                    // we need not read more data in case we have read less data than buffer size
                    if n < buffer_size {
                        // let us only append the data how much we have read rather than complete existing buffer data
                        // as n is less than buffer size
                        request_buffer.append(&mut buffer[..n].to_vec()); // convert slice into vec
                    } else {
                        // append complete buffer vec data into request_buffer vec as n == buffer_size
                        request_buffer.append(&mut buffer);
            Err(e) => {
                println!("Error in reading stream data: {:?}", e);

    (request_buffer, request_len)


  • Modifying/replacing Request Headers
  • Modifying/replacing Reponse Headers


~174K SLoC