swifter
swifter copied to clipboard
`HttpRequest.address` doesn't contain the requested URL
I'd like to access the complete URL address inside the route callback. So here is an example code:
let server = HttpServer(0)
server["hello-world"] = { request in
debugPrint(request.address)
return HttpResponse.ok(.text("<html string>"))
}
server.start()
but after visiting the registered address (e.g. http://127.0.0.1:66577/hello-world?test=1
), the request.path
, request.headers
, request.queryParams
properties are parsed and set correctly, just the request.address
contains a strange string - something like ::c080:d00:60:0
instead of the visited URL (http://127.0.0.1:66577/hello-world?test=1
in my case).
Although the HttpRequest.address
property is not documented, I'm assuming that it should contain the complete URL of the request. Am I right? Or if the HttpRequest.address
is used for something different, how can I get the visited URL?
When starting your server you can do so like: try server.start(9080, forceIPv4: true) For me this made the request.address show the IP address of the request i.e. 127.0.0.1. If you combine with request.path you should be able to start to rebuild the request.