apple / swift-http-types

Version-independent HTTP currency types for Swift
Apache License 2.0
894 stars 47 forks source link

How do you handle query string in the path #19

Closed BajaCali closed 1 year ago

BajaCali commented 1 year ago

Hello, it looks like this package is achieving mainly http2-like structures. In my case I use query string and I am having hard time to use this package along.

Am I using it wrong? How can I easily add a param to the query part of a URL of an HTTPRequest?

Thanks in advance for answer.

Lukasa commented 1 year ago

If you add a dependency on and then import HTTPTypesFoundation, you get a url accessor on HTTPRequest that you can get and set. This will let you modify all those fields at once, and add query parameters as needed.

guoye-zhang commented 1 year ago

HTTP :path pseudo header is actually the request target which includes the query as well. Maybe we should consider renaming the property.

https://datatracker.ietf.org/doc/html/rfc9113#name-request-pseudo-header-field

BajaCali commented 1 year ago

I would rather see the query part completely separately in the HTTP/2 to be honest. However, for my use-case I have created a builder of HTTPRequest, where I can add the query parameters and update the request as the call side wishes. Only downside is that I have to check whether there actually is a query in the :path pseudo header or has been added. In my implementation I check that only at builder init, which inits with a request.

Thanks for answers. Marking as resolved.