GithubHelp home page GithubHelp logo

Comments (8)

0xFar5eer avatar 0xFar5eer commented on May 18, 2024

This is the test code I use:

use std::time::Duration;

#[tokio::main]
async fn main() {
    let client = reqwest::Client::builder()
        .danger_accept_invalid_certs(true)
        .proxy(reqwest::Proxy::all("http://user:pass@localhost:3000/some/path").unwrap())
        .build()
        .unwrap();
    let rest_request_url = "https://www.test-site.com/foo/bar/123";
    let resp = client
        .get(rest_request_url)
        .timeout(Duration::from_secs(180))
        .send()
        .await;

    println!("{:#?}", resp);
}

This is the parameters output:

req: Request {
    method: GET,
    uri: https://www.test-site.com/foo/bar/123,
    version: HTTP/1.1,
    headers: {
        "accept": "*/*",
        "host": "www.test-site.com",
    },
    body: Body(
        Empty,
    ),
}
ctx: HttpContext {
    client_addr: 127.0.0.1:64685,
}

from hudsucker.

0xFar5eer avatar 0xFar5eer commented on May 18, 2024

Based on auth I would like to throw 407 errors if user is not authenticated.
And based on path uri load different settings.
Appears these parameters are passed on HTTP1.1 Connect request but I don't see how to handle those here.
Can you suggest me any tricks to do that with less blood?

from hudsucker.

omjadas avatar omjadas commented on May 18, 2024

What you would want to look at would be the Proxy-Authorization header. I think at the moment this would only really work for HTTP (not HTTPS) traffic, since CONNECT requests are not currently passed through the handle_request handler.

async fn handle_request(
    &mut self,
    _ctx: &HttpContext,
    req: Request<Body>,
) -> RequestOrResponse {
    use hudsucker::hyper::{self, http};

    if req.uri().scheme() == Some(&http::uri::Scheme::HTTP) {
        let auth = req.headers().get(hyper::header::PROXY_AUTHORIZATION);

        match auth {
            Some(auth) => {
                todo!("verify auth header");
            }
            None => {
                todo!("407")
            }
        }
    } else {
        todo!();
    }
}

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization

In regards to using a path, I don't believe it is possible to specify a path for a HTTP proxy, I assume reqwest would just be discarding it. A few things that could be done would be to have different proxies hosted on different ports, or to use a custom header instead of a path (assuming you are able to add a custom header in your use case).

from hudsucker.

0xFar5eer avatar 0xFar5eer commented on May 18, 2024

What you would want to look at would be the Proxy-Authorization header. I think at the moment this would only really work for HTTP (not HTTPS) traffic, since CONNECT requests are not currently passed through the handle_request handler.

async fn handle_request(
    &mut self,
    _ctx: &HttpContext,
    req: Request<Body>,
) -> RequestOrResponse {
    use hudsucker::hyper::{self, http};

    if req.uri().scheme() == Some(&http::uri::Scheme::HTTP) {
        let auth = req.headers().get(hyper::header::PROXY_AUTHORIZATION);

        match auth {
            Some(auth) => {
                todo!("verify auth header");
            }
            None => {
                todo!("407")
            }
        }
    } else {
        todo!();
    }
}

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization

In regards to using a path, I don't believe it is possible to specify a path for a HTTP proxy, I assume reqwest would just be discarding it. A few things that could be done would be to have different proxies hosted on different ports, or to use a custom header instead of a path (assuming you are able to add a custom header in your use case).

Yeah I guess CONNECT handling for https traffic would be nice feature to have.

from hudsucker.

omjadas avatar omjadas commented on May 18, 2024

Yeah I guess CONNECT handling for https traffic would be nice feature to have.

I have pushed 35aca05 to main, which passes CONNECT requests to the same handle_request handler. I will most likely cut a release in the coming days.

from hudsucker.

0xFar5eer avatar 0xFar5eer commented on May 18, 2024

Perfect thanks!
Also could you msg me in telegram http://t.me/Far5eer
I have a few questions about possibility to hire you for some rust projects.

Yeah I guess CONNECT handling for https traffic would be nice feature to have.

I have pushed 35aca05 to main, which passes CONNECT requests to the same handle_request handler. I will most likely cut a release in the coming days.

from hudsucker.

omjadas avatar omjadas commented on May 18, 2024

v0.18.0 has been released which should make this possible to do.

from hudsucker.

0xFar5eer avatar 0xFar5eer commented on May 18, 2024

Is it possible to to hire you part-time for a project based on hudsucker?
I am sure you can code it in an a few evenings but I am willing to pay for it :)
And I don't want to make public request feature for that.

Can you drop a message to my discord: 0xFar5eer#6504 ?

from hudsucker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.