Skip to content

Commit

Permalink
Merge pull request #12516 from jetty/jetty-12.0.x-12429-caseInsensiti…
Browse files Browse the repository at this point in the history
…veHeadersWebSocket2

WebSocket cleanups from PR #12441
  • Loading branch information
lachlan-roberts authored Nov 15, 2024
2 parents 26b9949 + 502f511 commit 24580b3
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@
public class DelegatedJettyClientUpgradeRequest implements UpgradeRequest
{
private final CoreClientUpgradeRequest delegate;
private final Map<String, List<String>> headers;

public DelegatedJettyClientUpgradeRequest(CoreClientUpgradeRequest delegate)
{
this.delegate = delegate;
this.headers = HttpFields.asMap(delegate.getHeaders());
}

@Override
Expand Down Expand Up @@ -79,7 +81,7 @@ public List<String> getHeaders(String name)
@Override
public Map<String, List<String>> getHeaders()
{
return HttpFields.asMap(delegate.getHeaders());
return headers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
public class DelegatedJettyClientUpgradeResponse implements UpgradeResponse
{
private final Response delegate;
private final Map<String, List<String>> headers;

public DelegatedJettyClientUpgradeResponse(Response response)
{
this.delegate = response;
this.headers = HttpFields.asMap(delegate.getHeaders());
}

@Override
Expand Down Expand Up @@ -65,7 +67,7 @@ public List<String> getHeaders(String name)
@Override
public Map<String, List<String>> getHeaders()
{
return HttpFields.asMap(delegate.getHeaders());
return headers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
class UpgradeRequestDelegate implements UpgradeRequest
{
private final ServerUpgradeRequest request;
private final Map<String, List<String>> headers;

UpgradeRequestDelegate(ServerUpgradeRequest request)
{
this.request = request;
this.headers = HttpFields.asMap(request.getHeaders());
}

@Override
Expand Down Expand Up @@ -72,7 +74,7 @@ public int getHeaderInt(String name)
@Override
public Map<String, List<String>> getHeaders()
{
return HttpFields.asMap(request.getHeaders());
return headers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
class UpgradeResponseDelegate implements UpgradeResponse
{
private final ServerUpgradeResponse response;
private final Map<String, List<String>> headers;

UpgradeResponseDelegate(ServerUpgradeResponse response)
{
this.response = response;
this.headers = HttpFields.asMap(response.getHeaders());
}

@Override
Expand Down Expand Up @@ -62,7 +64,7 @@ public Set<String> getHeaderNames()
@Override
public Map<String, List<String>> getHeaders()
{
return HttpFields.asMap(response.getHeaders());
return headers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ public class JsrHandshakeRequest implements HandshakeRequest
{
private final ServerUpgradeRequest delegate;
private final HttpServletRequest httpServletRequest;
private final Map<String, List<String>> headers;
private Map<String, List<String>> parameterMap;

public JsrHandshakeRequest(ServerUpgradeRequest req)
{
this.delegate = req;
this.httpServletRequest = (HttpServletRequest)req
.getAttribute(WebSocketConstants.WEBSOCKET_WRAPPED_REQUEST_ATTRIBUTE);
this.headers = HttpFields.asMap(delegate.getHeaders());
}

@Override
public Map<String, List<String>> getHeaders()
{
return HttpFields.asMap(delegate.getHeaders());
return headers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class DelegatedServerUpgradeRequest implements JettyServerUpgradeRequest
private final ServerUpgradeRequest upgradeRequest;
private final HttpServletRequest httpServletRequest;
private final Principal userPrincipal;
private final Map<String, List<String>> headers;
private List<HttpCookie> cookies;
private Map<String, List<String>> parameterMap;

Expand All @@ -57,6 +58,7 @@ public DelegatedServerUpgradeRequest(ServerUpgradeRequest request)
this.upgradeRequest = request;
this.queryString = httpServletRequest.getQueryString();
this.userPrincipal = httpServletRequest.getUserPrincipal();
this.headers = HttpFields.asMap(upgradeRequest.getHeaders());

try
{
Expand Down Expand Up @@ -121,7 +123,7 @@ public int getHeaderInt(String name)
@Override
public Map<String, List<String>> getHeaders()
{
return HttpFields.asMap(upgradeRequest.getHeaders());
return headers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.jetty.ee10.websocket.server.internal;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -35,22 +34,15 @@ public class DelegatedServerUpgradeResponse implements JettyServerUpgradeRespons
{
private final ServerUpgradeResponse upgradeResponse;
private final HttpServletResponse httpServletResponse;
private final boolean isUpgraded;
private final Map<String, List<String>> headers;

public DelegatedServerUpgradeResponse(ServerUpgradeResponse response)
{
this(response, false);
}

public DelegatedServerUpgradeResponse(ServerUpgradeResponse response, boolean isUpgraded)
{
upgradeResponse = response;
this.isUpgraded = isUpgraded;
ServletContextResponse servletContextResponse = Response.as(response, ServletContextResponse.class);
this.httpServletResponse = (HttpServletResponse)servletContextResponse.getRequest()
.getAttribute(WebSocketConstants.WEBSOCKET_WRAPPED_RESPONSE_ATTRIBUTE);
headers = HttpFields.asMap(upgradeResponse.getHeaders());
this.headers = HttpFields.asMap(upgradeResponse.getHeaders());
}

@Override
Expand Down Expand Up @@ -100,7 +92,7 @@ public Set<String> getHeaderNames()
@Override
public Map<String, List<String>> getHeaders()
{
return isUpgraded ? Collections.unmodifiableMap(headers) : headers;
return headers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public FrameHandler newFrameHandler(Object websocketPojo, ServerUpgradeRequest u
{
JettyWebSocketFrameHandler frameHandler = super.newJettyFrameHandler(websocketPojo);
frameHandler.setUpgradeRequest(new DelegatedServerUpgradeRequest(upgradeRequest));
frameHandler.setUpgradeResponse(new DelegatedServerUpgradeResponse(upgradeResponse, true));
frameHandler.setUpgradeResponse(new DelegatedServerUpgradeResponse(upgradeResponse));
return frameHandler;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ public class JsrHandshakeRequest implements HandshakeRequest
{
private final ServerUpgradeRequest delegate;
private final HttpServletRequest httpServletRequest;
private final Map<String, List<String>> headers;
private Map<String, List<String>> parameterMap;

public JsrHandshakeRequest(ServerUpgradeRequest req)
{
this.delegate = req;
this.httpServletRequest = (HttpServletRequest)req
.getAttribute(WebSocketConstants.WEBSOCKET_WRAPPED_REQUEST_ATTRIBUTE);
this.headers = HttpFields.asMap(delegate.getHeaders());
}

@Override
public Map<String, List<String>> getHeaders()
{
return HttpFields.asMap(delegate.getHeaders());
return headers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@
public class DelegatedJettyClientUpgradeRequest implements UpgradeRequest
{
private final CoreClientUpgradeRequest delegate;
private final Map<String, List<String>> headers;

public DelegatedJettyClientUpgradeRequest(CoreClientUpgradeRequest delegate)
{
this.delegate = delegate;
this.headers = HttpFields.asMap(delegate.getHeaders());
}

@Override
Expand Down Expand Up @@ -79,7 +81,7 @@ public List<String> getHeaders(String name)
@Override
public Map<String, List<String>> getHeaders()
{
return HttpFields.asMap(delegate.getHeaders());
return headers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
public class DelegatedJettyClientUpgradeResponse implements UpgradeResponse
{
private final Response delegate;
private final Map<String, List<String>> headers;

public DelegatedJettyClientUpgradeResponse(Response response)
{
this.delegate = response;
this.headers = HttpFields.asMap(delegate.getHeaders());
}

@Override
Expand Down Expand Up @@ -65,7 +67,7 @@ public List<String> getHeaders(String name)
@Override
public Map<String, List<String>> getHeaders()
{
return HttpFields.asMap(delegate.getHeaders());
return headers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class DelegatedServerUpgradeRequest implements JettyServerUpgradeRequest
private final String queryString;
private final ServerUpgradeRequest upgradeRequest;
private final HttpServletRequest httpServletRequest;
private final Map<String, List<String>> headers;
private List<HttpCookie> cookies;
private Map<String, List<String>> parameterMap;

Expand All @@ -55,6 +56,7 @@ public DelegatedServerUpgradeRequest(ServerUpgradeRequest request)
.getAttribute(WebSocketConstants.WEBSOCKET_WRAPPED_REQUEST_ATTRIBUTE);
this.upgradeRequest = request;
this.queryString = httpServletRequest.getQueryString();
this.headers = HttpFields.asMap(upgradeRequest.getHeaders());

try
{
Expand Down Expand Up @@ -114,7 +116,7 @@ public int getHeaderInt(String name)
@Override
public Map<String, List<String>> getHeaders()
{
return HttpFields.asMap(upgradeRequest.getHeaders());
return headers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ public class DelegatedServerUpgradeResponse implements JettyServerUpgradeRespons
{
private final ServerUpgradeResponse upgradeResponse;
private final HttpServletResponse httpServletResponse;
private final Map<String, List<String>> headers;

public DelegatedServerUpgradeResponse(ServerUpgradeResponse response)
{
this.upgradeResponse = response;
this.httpServletResponse = (HttpServletResponse)response.getRequest()
.getAttribute(WebSocketConstants.WEBSOCKET_WRAPPED_RESPONSE_ATTRIBUTE);
this.headers = HttpFields.asMap(upgradeResponse.getHeaders());
}

@Override
Expand Down Expand Up @@ -87,7 +89,7 @@ public Set<String> getHeaderNames()
@Override
public Map<String, List<String>> getHeaders()
{
return HttpFields.asMap(upgradeResponse.getHeaders());
return headers;
}

@Override
Expand Down

0 comments on commit 24580b3

Please sign in to comment.