Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed incorrect Sec-WebSocket-Origin header for v13, see #9134 #9312

Merged
merged 1 commit into from Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -189,7 +189,7 @@ public WebSocketClientHandshaker13(URI webSocketURL, WebSocketVersion version, S
* Upgrade: websocket
* Connection: Upgrade
* Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
* Sec-WebSocket-Origin: http://example.com
* Origin: http://example.com
* Sec-WebSocket-Protocol: chat, superchat
* Sec-WebSocket-Version: 13
* </pre>
Expand Down Expand Up @@ -225,7 +225,7 @@ protected FullHttpRequest newHandshakeRequest() {
.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE)
.set(HttpHeaderNames.SEC_WEBSOCKET_KEY, key)
.set(HttpHeaderNames.HOST, websocketHostValue(wsURL))
.set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, websocketOriginValue(wsURL));
.set(HttpHeaderNames.ORIGIN, websocketOriginValue(wsURL));

String expectedSubprotocol = expectedSubprotocol();
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
Expand All @@ -251,7 +251,7 @@ protected FullHttpRequest newHandshakeRequest() {
*
* @param response
* HTTP response returned from the server for the request sent by beginOpeningHandshake00().
* @throws WebSocketHandshakeException
* @throws WebSocketHandshakeException if handshake response is invalid.
*/
@Override
protected void verify(FullHttpResponse response) {
Expand Down
Expand Up @@ -115,7 +115,7 @@ public WebSocketServerHandshaker13(
* Upgrade: websocket
* Connection: Upgrade
* Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
* Sec-WebSocket-Origin: http://example.com
* Origin: http://example.com
* Sec-WebSocket-Protocol: chat, superchat
* Sec-WebSocket-Version: 13
* </pre>
Expand Down
Expand Up @@ -46,7 +46,7 @@ protected CharSequence[] getHandshakeHeaderNames() {
HttpHeaderNames.CONNECTION,
HttpHeaderNames.SEC_WEBSOCKET_KEY,
HttpHeaderNames.HOST,
HttpHeaderNames.SEC_WEBSOCKET_ORIGIN,
getOriginHeaderName(),
HttpHeaderNames.SEC_WEBSOCKET_VERSION,
};
}
Expand Down
Expand Up @@ -15,16 +15,24 @@
*/
package io.netty.handler.codec.http.websocketx;

import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;

import java.net.URI;

public class WebSocketClientHandshaker13Test extends WebSocketClientHandshaker07Test {

@Override
protected WebSocketClientHandshaker newHandshaker(URI uri, String subprotocol, HttpHeaders headers,
boolean absoluteUpgradeUrl) {
return new WebSocketClientHandshaker13(uri, WebSocketVersion.V13, subprotocol, false, headers,
1024, true, true, 10000,
absoluteUpgradeUrl);
}

@Override
protected CharSequence getOriginHeaderName() {
return HttpHeaderNames.ORIGIN;
}

}
Expand Up @@ -138,7 +138,11 @@ public FullHttpRequest build() {
headers.set(HttpHeaderNames.SEC_WEBSOCKET_KEY, key);
}
if (origin != null) {
headers.set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, origin);
if (version == WebSocketVersion.V13 || version == WebSocketVersion.V00) {
headers.set(HttpHeaderNames.ORIGIN, origin);
} else {
headers.set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, origin);
}
}
if (version != null) {
headers.set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, version.toHttpHeaderValue());
Expand Down