-
Notifications
You must be signed in to change notification settings - Fork 50
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
Conversion from relative HTTPRequest to absolute Foundation URL #36
Comments
I was wondering if the introduction of But it looks like the 5.9 compiler is smart enough: // No error, no warning, all inferences work as expected
func f(_ request: HTTPRequest, baseURL: URL) {
let a = request.url // inferred as URL?
let b = request.url(baseURL:) // inferred as (URL) -> URL?
let c = request.url(baseURL: baseURL) // inferred as URL?
} I'm not sure, though, if the inference of |
URL should always be absolute in an HTTP request. It does not make sense to have a request with a relative URL. I think this might be a bug in openapi-generator. |
@guoye-zhang @groue I think there might have been a small miscommunication here. The HTTPRequest created by the generator never has the necessary pseudoheaders set for the The full URL is constructed by the transport by taking the base URL (which is absolute) and appending the path and query to it. This is structured this way because it's very common for a REST API to be described as a list of paths and methods, where the paths are e.g. I think @groue's ask is reasonable for an extra utils function in HTTPTypes, but it's up to @guoye-zhang to decide whether it's in scope for that library. This issue was only discovered when using the generator, but that's just because we're one of the adopters of HTTPTypes. There isn't a bug or anything in the generator that made this necessary, it's more about the API of HTTPTypes and a suggestion of extending it. @guoye-zhang, would you want to transfer the issue back and then decide what to do with it in the swift-http-types repo? |
Discussed with @czechboy0 offline, it's a common use in REST frameworks that we could consider supporting in the future |
Thank you @guoye-zhang.
Oh, I guess I said "relative url" because that concept was kind of relevant in the context, and because I never heard about HTTP/2 pseudo headers until today :-) In the end, I don't know how much my version of |
Hello,
This issue is a feature request for a new API in the HTTPTypesFoundation module:
I met a need for this API while using http://github.com/apple/swift-openapi-generator
When writing a
ClientMiddleware
that processes http requests performed throughURLSession
, I need an absoluteFoundation.URL
in order to use various services such asHTTPCookieStorage
.This package defines a
HTTPRequest.url
property that looks very promising.But the
HTTPRequest
I get from OpenAPIRuntime is not absolute. It is relative to a base URL, and itsurl
property is nil:Since my requests are performed through
URLSession
, I was pretty sure to find some code that turns a (request, baseURL) pair into an absoluteURL
, suitable forURLRequest
. Indeed, it is there.This code is not public, so I defined my own version, inspired from the above implementation:
Since the implementation is not quite trivial, I believe it is a good candidate for inclusion in
HTTPTypesFoundation
.What do you think?
The text was updated successfully, but these errors were encountered: