apple / swift-openapi-urlsession

URLSession transport for Swift OpenAPI Generator.
https://swiftpackageindex.com/apple/swift-openapi-urlsession/documentation
Apache License 2.0
160 stars 29 forks source link

[BUG] Fix: resolve issue with HTTP headers may lost some cookies #50

Closed anotheren closed 2 months ago

anotheren commented 3 months ago

Motivation

I use a custom ClientMiddleware to inject cookie for some APIs, but I found the final Request always lost some cookies.

https://github.com/apple/swift-http-types/blob/e6359663d11a5c7d2340ac81f2e025d5c5fb0e14/Sources/HTTPTypes/HTTPFields.swift#L190

The reason is that there may be more than one cookie in the HTTPRequest's headerFields. Before setting them to the URLRequest, you must join them together. Otherwise, only the last cookie will be effective due to simple overwriting.

Modifications

Check header.name before setting it to the URLRequest

Result

All cookies now work well.

Test Plan

Not yet.

czechboy0 commented 2 months ago

@anotheren let's close this and use #51, thanks for pushing for this fix! 👏