vapor / websocket-kit

WebSocket client library built on SwiftNIO
https://docs.vapor.codes/4.0/advanced/websockets/
MIT License
272 stars 79 forks source link

Do not add a `Content-Type` header to the HTTP upgrade request #127

Closed fumoboy007 closed 1 year ago

fumoboy007 commented 1 year ago

⚠️ WARNING: This release removes the hard-coded content-type header from the upgrade request. If you were relying on this you'll need to manually add it now, but since there's no body it shouldn't be required

Some WebSocket servers use the Content-Type header to determine which serialization format to use for its WebSocket messages. However, HTTPInitialRequestHandler adds a hard-coded Content-Type: text/plain; charset=utf-8 header to the WebSocket client’s HTTP upgrade request, so the client cannot customize the header value.

Given that the HTTP upgrade request body is empty, there is no need for HTTPInitialRequestHandler to add the Content-Type header. This will allow the client to add their own, if desired.

Fixes #126.

codecov-commenter commented 1 year ago

Codecov Report

Merging #127 (cd98161) into main (e0faccd) will decrease coverage by 4.66%. The diff coverage is 72.09%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #127 +/- ## ========================================== - Coverage 71.15% 66.50% -4.66% ========================================== Files 5 6 +1 Lines 475 600 +125 ========================================== + Hits 338 399 +61 - Misses 137 201 +64 ``` | [Impacted Files](https://codecov.io/gh/vapor/websocket-kit/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor) | Coverage Δ | | |---|---|---| | [...bSocketKit/Concurrency/WebSocket+Concurrency.swift](https://codecov.io/gh/vapor/websocket-kit/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9XZWJTb2NrZXRLaXQvQ29uY3VycmVuY3kvV2ViU29ja2V0K0NvbmN1cnJlbmN5LnN3aWZ0) | `29.78% <ø> (ø)` | | | [...urces/WebSocketKit/HTTPInitialRequestHandler.swift](https://codecov.io/gh/vapor/websocket-kit/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9XZWJTb2NrZXRLaXQvSFRUUEluaXRpYWxSZXF1ZXN0SGFuZGxlci5zd2lmdA==) | `67.44% <ø> (-0.74%)` | :arrow_down: | | [Sources/WebSocketKit/WebSocket+Connect.swift](https://codecov.io/gh/vapor/websocket-kit/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9XZWJTb2NrZXRLaXQvV2ViU29ja2V0K0Nvbm5lY3Quc3dpZnQ=) | `97.50% <ø> (ø)` | | | [Sources/WebSocketKit/WebSocketClient.swift](https://codecov.io/gh/vapor/websocket-kit/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9XZWJTb2NrZXRLaXQvV2ViU29ja2V0Q2xpZW50LnN3aWZ0) | `76.80% <66.66%> (+8.83%)` | :arrow_up: | | [Sources/WebSocketKit/WebSocket.swift](https://codecov.io/gh/vapor/websocket-kit/pull/127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9XZWJTb2NrZXRLaXQvV2ViU29ja2V0LnN3aWZ0) | `72.11% <81.25%> (+0.32%)` | :arrow_up: |
0xTim commented 1 year ago

SemVer minor due to the behaviour change. Had a check around and it should be fine

VaporBot commented 1 year ago

These changes are now available in 2.7.0