Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose source ip of http request #538

Closed
indexds opened this issue Dec 27, 2024 · 2 comments · Fixed by #539
Closed

Expose source ip of http request #538

indexds opened this issue Dec 27, 2024 · 2 comments · Fixed by #539
Labels
enhancement New feature or request

Comments

@indexds
Copy link
Contributor

indexds commented Dec 27, 2024

Hi, I'd like to restrict the traffic to my http server to a specific netif, this could be done easily if there was a way to check the source ip of a request to do control flow like;

http_server.fn_handler("/", Method::Get, move |mut request| {

    let html = "hello world";

    let connection = request.connection();

    if connection.get_src_ip()? != Ipv4::new(10, 10, 10, 1) {
        return Err(anyhow::anyhow!("Source ip forbidden"));
    }

    connection.initiate_response(200, Some("OK"), &[("Content-Type", "text/html")])?;

    connection.write(html.as_bytes())?;

    Ok::<(), Error>(())
})?;

I've looked at this forum post which is very interesting but doesn't really help me parse the very opaque http/server.rs to see where I would put this potential method.

  • Would you like to implement this feature? yes

A nudge in the right direction would be helpful, or maybe this isn't necessary at all and there's already a way to check this that I haven't found. Who knows.

@indexds indexds added the enhancement New feature or request label Dec 27, 2024
@indexds
Copy link
Contributor Author

indexds commented Dec 27, 2024

Ok so I think I've somewhat figured it out, in http/server.rs there's a;

pub struct EspHttpRawConnection<'a>(&'a mut httpd_req_t);

which is what we want. Now to write the method..

@indexds
Copy link
Contributor Author

indexds commented Dec 28, 2024

Well. That wasn't so hard after all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant