# Retrieving HTTP response headers during a typed WebSocket client upgrade

**URL:** <https://forums.swift.org/t/retrieving-http-response-headers-during-a-typed-websocket-client-upgrade/68529>\
**Category:** SwiftNIO\
**Tags:** websocket\
**Created:** [November 18, 2023, 5:21pm UTC](https://forums.swift.org/t/retrieving-http-response-headers-during-a-typed-websocket-client-upgrade/68529 "2023-11-18T17:21:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![samalone](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/samalone/32/32395_2.png) [@samalone](https://forums.swift.org/u/samalone)\
**Post date:** [November 18, 2023, 5:21pm UTC](https://forums.swift.org/t/retrieving-http-response-headers-during-a-typed-websocket-client-upgrade/68529/1 "2023-11-18T17:21:51Z")

</div>

I'm trying to use the new typed WebSocket upgraders in NIO, and I can't figure out how to retrieve the response headers sent by the server during the initial HTTP phase of the WebSocket upgrade process.

I adapted my client code from the sample in NIO. It currently looks like:

```swift
        private func openClientChannel(host: String, port: Int) async throws -> ServerConnection {
            let bootstrap = PlatformBootstrap(group: ClientManager.group)
            let upgradeResult = try await bootstrap.connect(host: host, port: port) { channel in
                channel.eventLoop.makeCompletedFuture {
                    let upgrader = NIOAsyncWebSockets.NIOTypedWebSocketClientUpgrader<UpgradeResult> { channel, responseHead in
                        self.system.logger.trace("upgrading client channel to server on \(TaskPath.current)")
                        self.system.logger.trace("responseHead = \(responseHead)")
                        return channel.eventLoop.makeCompletedFuture {
                            let asyncChannel = try WebSocketAgentChannel(wrappingChannelSynchronously: channel)
                            return UpgradeResult.websocket(ServerConnection(channel: asyncChannel, nodeID: NodeIdentity("bogus")))
                        }
                    }
                    
                    var headers = HTTPHeaders()
                    headers.add(name: "ActorSystemNodeID", value: self.system.nodeID.id)
                    headers.add(name: "Content-Type", value: "text/plain; charset=utf-8")
                    headers.add(name: "Content-Length", value: "0")
                    
                    let requestHead = HTTPRequestHead(
                        version: .http1_1,
                        method: .GET,
                        uri: "/",
                        headers: headers
                    )
                    
                    let clientUpgradeConfiguration = NIOTypedHTTPClientUpgradeConfiguration(
                        upgradeRequestHead: requestHead,
                        upgraders: [upgrader],
                        notUpgradingCompletionHandler: { channel in
                            channel.eventLoop.makeCompletedFuture {
                                return UpgradeResult.notUpgraded
                            }
                        }
                    )
                    
                    let negotiationResultFuture = try channel.pipeline.syncOperations.configureUpgradableHTTPClientPipeline(
                        configuration: .init(upgradeConfiguration: clientUpgradeConfiguration)
                    )
                    
                    return negotiationResultFuture
                }
            }
            
            switch try await upgradeResult.get() {
            case .websocket(let serverConnection):
                return serverConnection
            case .notUpgraded:
                throw WebSocketActorSystemError.failedToUpgrade
            }
        }
    }

```

Somewhere in here, I need to access the HTTP response headers from the initial HTTP connection. I had hoped they would be in the second argument to the NIOTypedWebSocketClientUpgrader upgradePipelineHandler, but those seem to be for a later phase of the upgrade process.

Is there some way to access those response headers?
