Netty: Provide access to HTTP response status and headers when error occurs during websocket upgrade

Created on 5 Oct 2020  路  3Comments  路  Source: netty/netty

I would like access to the HTTP response status and headers when an error response is returned from the server during websocket upgrade.

Currently, when the websocket upgrade response indicates the upgrade failed, netty throws a WebSocketHandshakeException with a message indicating the problem. However, the exception does not provide access to the HTTP response status/headers.

https://github.com/netty/netty/blob/69b44c6d06d4449920b6b8990b0f6e0473f3532b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java#L273-L291

A concrete use case where providing clients access to the response status/headers would be useful is when an OAuth 2.0 bearer token is used for authentication. The server will return a 401 response if the token is invalid, and will provide additional details in the WWW-Authenticate header. (See RFC-6750 Section 3). If the headers indicate that the token has expired, then clients can act upon it to remove the token from its cache, retrieve a new token, and then retry the websocket connection. Currently this is not possible, since the WebSocketHandshakeException does not provide access to the response status/headers.

Expected behavior

Able to access Websocket upgrade HTTP response status and headers when websocket upgrades fail.

Actual behavior

A WebSocketHandshakeException is thrown, with a message indicating why the failure occurred. The WebSocketHandshakeException does not currently provide access to the http response status and headers.

Steps to reproduce

Issue a websocket upgrade request to a server that returns a 401 response.

Netty version

4.1.52

All 3 comments

@philsttr hi i think this is related to https://github.com/netty/netty/issues/10277, i'll try to do PR at my suggestion.

@philsttr Could you please check fix and close issue if everything is ok.

Fixed in #10646

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carl-mastrangelo picture carl-mastrangelo  路  5Comments

esfomeado picture esfomeado  路  6Comments

normanmaurer picture normanmaurer  路  3Comments

anuchandy picture anuchandy  路  5Comments

gliwka picture gliwka  路  3Comments