Client address #3
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The ServerHttpRequest struct currently has no designated way to store the address of the remote client the request originated from.
This information would be crucial for auth logs (e.g. to be fed to security tools like Fail2Ban) or maybe web application firewalls, and handy for geo IP purposes.
Alternatives
Obviously, this information could be provided by a server to a request handler through alternative means (like a wrapper struct containing the ServerHttpRequest and additional info), though the naming might not be as adequate in this case.
Other implementations
PSR-7 handles this through the rather clunky
ServerRequestInterface::getServerParams()
method.I am thinking of doing something like this, and adding
const InternetAddress clientAddress;
to theServerHttpRequest
:It would mean that each request takes up an additional 16 bytes for the request, but I prefer this over the polymorphic class-based approach in Phobos.
I'm going to go ahead and commit this along with the HTTP method update, and feel free to close if you're satisfied, or you are free to submit your own PR on it.
Yeah, I don’t think we have to go with classes here either.
A relevant limitation if your union solution is, though, that it doesn’t support Unix domain sockets.
I’m not sure whether we should add them to the union as well (and replace
isIPv6
with an enum-based type tag or something) or rather rethink the task as a whole.(Another minor issue is that unions aren’t accessible in
@safe
code.)Two ideas that come to mind are:
X-Forwarded-For
). The obvious limitation is that the value has to be either serialized to string or be a string in the first place.PSR-7 has this and it works well in PHP through dynamic typing; in D however probably this requires some sort of clunk.
oceandrift-http uses
std.variant.Variant[string]
and usage isn’t too pretty (and@system
).Both could also be useful when implementing a middleware routing model.
Nevertheless, both also have apparent limitations/issues.
Given that this library already uses
std.typecons
, would it be acceptable to usestd.sumtype
for the implementation here?I'd actually prefer to avoid using the existing standard library where at all possible (so that this code is largely compatible with Phobos3 or whatever).
In recent commits, I've removed the usage of
std.typecons
, and instead ofstd.sumtype
, if you read theaddress.d
file, you'll see that I make a barebones compound struct containing each possible address type. Realistically it's less than 32 bytes of total information, so I think it's still acceptable overhead.