vapor / websocket-kit

WebSocket client library built on SwiftNIO

Home Page:https://docs.vapor.codes/4.0/advanced/websockets/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`HTTPInitialRequestHandler` should not add a `Content-Type` header

fumoboy007 opened this issue · comments

Describe the bug

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.

To Reproduce

try await WebSocket.connect(to: url,
                            on: eventLoopGroup) { webSocket in
  // …
}

Expected behavior

The HTTP upgrade request should not have a Content-Type header.

Environment

  • Vapor Framework version: 4.69.2
  • Vapor Toolbox version: 18.6.0
  • OS version: macOS 12.6.3