rawhat / mist

gleam HTTP server. because it glistens on a web
Apache License 2.0
260 stars 11 forks source link

Get client IP address #10

Closed lpil closed 10 months ago

lpil commented 1 year ago

Hello!

Is there a way to the the IP address of the requester?

Thanks, Louis

rawhat commented 1 year ago

Currently, unless it's provided as a header, it is not accessible.

I think I'd have to make a custom Request type with that as a field on it (which might make sense, this isn't the first item like this to come up).

Does that make sense to you?

lpil commented 1 year ago

Other options could be to have a special body type or to add it as a header perhaps.

What other things like this are there?

rawhat commented 1 year ago

Sorry I left this open for so long...

It seems like:

Happy to peruse some more to more fully flesh this out. I do think since the exported functions to actually handle the req->resp in mist could be inferred, I could pretty easily make a new type that extends the gleam/http one? If you don't like that idea, I am definitely open to others!

lpil commented 1 year ago

I think it may be nicer to put any additional data in the body field rather than as a wrapper around Request/Response as otherwise no functions that work with gleam_http will work with Mist without an adapter. Or alternatively it could be a second data structure passed alongside the request? I'm unsure what is the best design overall.

Sorry I left this open for so long...

Nonsense! No rush at all and I'm super grateful for this fab project of yours 💜

rawhat commented 1 year ago

Hmm yeah, I see what you mean. I agree it would be weird to require some transformation to work with gleam/http, but also overloading the req.body also seems a little strange. I'll reference what else is included in some of these other implementations, and maybe it'll become clearer. To your latter suggestion, something like an additional ConnectionInfo or similar might make sense? Some of the handlers are already passed the state, so it could be included as part of that / an additional argument. Will think on it!

rawhat commented 10 months ago

This is supported now 🎉