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
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
'sheaderFields
. Before setting them to theURLRequest
, 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 theURLRequest
Result
All cookies now work well.
Test Plan
Not yet.