Skip to content

Commit

Permalink
Issue #5044 - extend Jetty WS API Request/Response interfaces for jet…
Browse files Browse the repository at this point in the history
…ty-websocket-server

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Jul 30, 2020
1 parent 3074aa7 commit ce8cb06
Show file tree
Hide file tree
Showing 14 changed files with 396 additions and 596 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,6 @@ public interface UpgradeRequest
*/
URI getRequestURI();

/**
* Access the Servlet HTTP Session (if present)
* <p>
* Note: Never present on a Client UpgradeRequest.
*
* @return the Servlet HTTPSession on server side UpgradeRequests
*/
Object getSession();

/**
* Get the list of offered WebSocket sub-protocols.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package org.eclipse.jetty.websocket.api;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -30,14 +29,6 @@
*/
public interface UpgradeResponse
{
/**
* Add a header value to the response.
*
* @param name the header name
* @param value the header value
*/
void addHeader(String name, String value);

/**
* Get the accepted WebSocket protocol.
*
Expand Down Expand Up @@ -88,57 +79,4 @@ public interface UpgradeResponse
* @return the status code
*/
int getStatusCode();

/**
* Issue a forbidden upgrade response.
* <p>
* This means that the websocket endpoint was valid, but the conditions to use a WebSocket resulted in a forbidden
* access.
* <p>
* Use this when the origin or authentication is invalid.
*
* @param message the short 1 line detail message about the forbidden response
* @throws IOException if unable to send the forbidden
*/
void sendForbidden(String message) throws IOException;

/**
* Set the accepted WebSocket Protocol.
*
* @param protocol the protocol to list as accepted
*/
void setAcceptedSubProtocol(String protocol);

/**
* Set the list of extensions that are approved for use with this websocket.
* <p>
* Notes:
* <ul>
* <li>Per the spec you cannot add extensions that have not been seen in the {@link UpgradeRequest}, just remove
* entries you don't want to use</li>
* <li>If this is unused, or a null is passed, then the list negotiation will follow default behavior and use the
* complete list of extensions that are
* available in this WebSocket server implementation.</li>
* </ul>
*
* @param extensions the list of extensions to use.
*/
void setExtensions(List<ExtensionConfig> extensions);

/**
* Set a header
* <p>
* Overrides previous value of header (if set)
*
* @param name the header name
* @param value the header value
*/
void setHeader(String name, String value);

/**
* Set the HTTP Response status code
*
* @param statusCode the status code
*/
void setStatusCode(int statusCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,6 @@ public URI getRequestURI()
return requestURI;
}

@Override
public Object getSession()
{
throw new UnsupportedOperationException("HttpSession not available on Client request");
}

@Override
public List<String> getSubProtocols()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ public boolean isSecure()
return HttpClient.isSchemeSecure(delegate.getScheme());
}

@Override
public Object getSession()
{
return null;
}

@Override
public Principal getUserPrincipal()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package org.eclipse.jetty.websocket.client.impl;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -79,49 +78,13 @@ public int getStatusCode()
return this.delegate.getStatus();
}

@Override
public void addHeader(String name, String value)
{

}

@Override
public void sendForbidden(String message) throws IOException
{

}

@Override
public void setAcceptedSubProtocol(String protocol)
{

}

@Override
public List<ExtensionConfig> getExtensions()
{
List<String> rawExtensions = delegate.getHeaders().getValuesList(HttpHeader.SEC_WEBSOCKET_EXTENSIONS);
if (rawExtensions == null || rawExtensions.isEmpty())
return Collections.emptyList();

return rawExtensions.stream().map((parameterizedName) -> ExtensionConfig.parse(parameterizedName)).collect(Collectors.toList());
}

@Override
public void setExtensions(List<org.eclipse.jetty.websocket.api.extensions.ExtensionConfig> extensions)
{

}

@Override
public void setHeader(String name, String value)
{

}

@Override
public void setStatusCode(int statusCode)
{

return rawExtensions.stream().map(ExtensionConfig::parse).collect(Collectors.toList());
}
}
Loading

0 comments on commit ce8cb06

Please sign in to comment.