Coder Social home page Coder Social logo

Comments (12)

seanmonstar avatar seanmonstar commented on May 5, 2024 1

For reference, here's that branch I started: https://github.com/seanmonstar/warp/compare/addr?expand=1

It doesn't need the local hyper dependency any more, and doesn't actually add a new filter yet, just makes the address available in the Route. Running a pipelined benchmark against the branch suggests some slow down, which is not desirable.

from warp.

seanmonstar avatar seanmonstar commented on May 5, 2024 1

Note that hyper gained the ability for a MakeService to receive a reference to the connection when making a new Service, so it could be fairly simple to implement in warp now.

A blocker is that warp allows any transport type that implements AsyncRead + AsyncWrite, which doesn't provide a way to access the remote address. We could add a trait like Transport: AsyncRead + AsyncWrite, and new server constructors with the new bounds.

from warp.

seanmonstar avatar seanmonstar commented on May 5, 2024

Good idea! Hm, should this try to be smarter, by checking X-Forwarded-For and such, or simply return the value from the TcpStream?

from warp.

markcol avatar markcol commented on May 5, 2024

If you don't use the x-forwarded-for header contents, aren't you going to be returning the address of the last proxy that touched the request, rather than the actual client address?

from warp.

kamalmarhubi avatar kamalmarhubi commented on May 5, 2024

I think a collection of filters would make sense here:

  • one that gets the address of the connected socket
  • one that gets the address from X-Forwarded-For (returns an iterator?)
  • one that gets the address from Forwarded (https://tools.ietf.org/html/rfc7239)

I don't think a decision should be made for the user on whether they trust the proxy header or not. Some friendly default combinations could be useful though, eg Forwarded or X-Forwarded-For if available, else socket.

from warp.

seanmonstar avatar seanmonstar commented on May 5, 2024

@markcol yes, but that's only an issue if proxies are involved. The other side is that you're trusting that a proxy was in place and it would have had to look at the remote address of its TcpStream. If it's done automatically and there is no proxy, you'd be trusting an end user that could forge a fake header.

It seems like both are useful, depending on your deployment.

from warp.

seanmonstar avatar seanmonstar commented on May 5, 2024

I have a branch a branch exploring adding this that I can push tomorrow. It might be hurting performance slightly, making me wish for a solution that doesn't do anything unless the filter was actually being used...

from warp.

kamalmarhubi avatar kamalmarhubi commented on May 5, 2024

Is this possible without changes to hyper? I didn't see any way to get at the address from Request that you get as a hyper::Service, which is why I started poking around hyper's code and issues.

from warp.

seanmonstar avatar seanmonstar commented on May 5, 2024

Yes it's possible, just not with hyper::Server. It requires creating the listener and using Http::serve_connection, so that the bound service could have grabbed the socket address of the connection first.

from warp.

kamalmarhubi avatar kamalmarhubi commented on May 5, 2024

@seanmonstar how are you benchmarking? in case I get to experiment a bit this weekend...

from warp.

seanmonstar avatar seanmonstar commented on May 5, 2024

The server program:

extern crate warp;

use warp::Filter;

fn main() {
    let text = warp::path("plaintext")
        .map(|| "Hello, World!");
    let json = warp::path("json")
        .map(|| warp::reply::json(&["Hello, World"]));
    let routes = text.or(json);

    warp::serve(routes)
        .unstable_pipeline()
        .run(([127, 0, 0, 1], 3030));
}

And then, using wrk with a pipeline script, something like wrk -t1 -d10 -c50 -s pipeline.lua http://127.0.0.1:3030/plaintext -- 16. You can fiddle with the -c argument some to find a good baseline on your machine for warp master, and then compare with the branch.

from warp.

andywwright avatar andywwright commented on May 5, 2024

@seanmonstar would you consider to make it as a feature? Those, for whom a client IP based routing is critical (like me) would switch it on and pay the penalty, and it wouldn't affect anyone else that way.

from warp.

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.