-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Technically this removes Sec-Websocket-Origin, as that's what the current version of Netty uses. We'll need to change this on 1.18+. Closes ##1197.
- Loading branch information
Showing
2 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/dan200/computercraft/core/apis/http/websocket/NoOriginWebSocketHanshakder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* This file is part of ComputerCraft - http://www.computercraft.info | ||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission. | ||
* Send enquiries to dratcliffe@gmail.com | ||
*/ | ||
package dan200.computercraft.core.apis.http.websocket; | ||
|
||
import io.netty.handler.codec.http.FullHttpRequest; | ||
import io.netty.handler.codec.http.HttpHeaderNames; | ||
import io.netty.handler.codec.http.HttpHeaders; | ||
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker13; | ||
import io.netty.handler.codec.http.websocketx.WebSocketVersion; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* A version of {@link WebSocketClientHandshaker13} which doesn't add the {@link HttpHeaderNames#SEC_WEBSOCKET_ORIGIN} | ||
* header to the original HTTP request. | ||
*/ | ||
public class NoOriginWebSocketHanshakder extends WebSocketClientHandshaker13 | ||
{ | ||
public NoOriginWebSocketHanshakder( URI webSocketURL, WebSocketVersion version, String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength ) | ||
{ | ||
super( webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength ); | ||
} | ||
|
||
@Override | ||
protected FullHttpRequest newHandshakeRequest() | ||
{ | ||
FullHttpRequest request = super.newHandshakeRequest(); | ||
HttpHeaders headers = request.headers(); | ||
|
||
if( !customHeaders.contains( HttpHeaderNames.SEC_WEBSOCKET_ORIGIN ) ) | ||
{ | ||
headers.remove( HttpHeaderNames.SEC_WEBSOCKET_ORIGIN ); | ||
} | ||
return request; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters