public interface Server
The "exchange" object is a request scoped object provided by the HTTP server to identify the request.
A Server implementation has to receive FrontController as
a dependency and call handle(...) on it when
a new request is made.
Note that the server will automatically remove any cache buster codes
from the request's path.
| Modifier and Type | Method and Description |
|---|---|
void |
addCookies(Object exchange,
Map<String,Cookie> cookies)
Adds cookies.
|
void |
addHttpAuthentication(String realmName,
String username,
String password)
Adds a user to an HTTP protected realm.
|
void |
addStaticResourceToServe(StaticResource<?> staticResource)
Adds a static resource to serve directly by the server.
|
void |
createHttpAuthenticationRealm(String pathPrefix,
String realmName)
Creates HTTP authentication protection (realm) for the
specified path prefix.
|
void |
end(Object exchange)
Ends the exchange.
|
void |
flushBytes(Object exchange,
byte[] bytes,
boolean end)
Flushes some bytes to the response.
|
boolean |
forceRequestSizeValidation(Object exchange)
Is the request size valid?
|
ContentTypeDefaults |
getContentTypeBestMatch(Object exchange)
Gets the best
Content-Type to use for the current request. |
Map<String,Cookie> |
getCookies(Object exchange)
Gets the current cookies.
|
Map<String,List<String>> |
getFormData(Object exchange)
The form data, if any.
|
String |
getFullUrlOriginal(Object exchange)
The full encoded URL of the original, non proxied, request, including the queryString.
|
String |
getFullUrlOriginal(Object exchange,
boolean keepCacheBusters)
The full encoded URL of the original, non proxied, request, including the queryString.
|
String |
getFullUrlProxied(Object exchange)
The full encoded URL of the potentially proxied request, including the queryString.
|
String |
getFullUrlProxied(Object exchange,
boolean keepCacheBusters)
The full encoded URL of the potentially proxied request, including the queryString.
|
Map<String,String> |
getHttpAuthenticationRealms()
Returns the existing HTTP authentication realms, the
key being the realm's name and the value being the
prefix path associated to this realm.
|
HttpMethod |
getHttpMethod(Object exchange)
Gets the HTTP method associated with the request.
|
Map<String,List<String>> |
getQueryStringParams(Object exchange)
Gets the queryString parameters.
|
InputStream |
getRawInputStream(Object exchange)
The raw InputStream of the current request.
|
Map<String,List<String>> |
getRequestHeaders(Object exchange)
The headers from the request.
|
String |
getRequestScheme(Object exchange)
Gets the request scheme, "http" for example.
|
Map<String,List<String>> |
getResponseHeaders(Object exchange)
Gets the response headers.
|
StaticResource<?> |
getStaticResourceServed(String urlPath)
Gets a static resource served directly by the server, using its path.
|
Set<StaticResource<?>> |
getStaticResourcesServed()
Gets all static resource served directly by the server.
|
Map<String,List<File>> |
getUploadedFiles(Object exchange)
The uploaded files, if any.
|
WebsocketEndpointManager |
getWebsocketEndpointManager(String endpointId)
Returns the manager for a Websockets endpoint.
|
List<WebsocketEndpointManager> |
getWebsocketEndpointManagers()
Returns the managers of the existing Websockets endpoints.
|
boolean |
isResponseClosed(Object exchange)
Is the response closed?
|
boolean |
isResponseHeadersSent(Object exchange)
Are the response headers sent?
|
boolean |
isRunning()
Is this server running (started)?
|
void |
removeAllStaticResourcesServed()
Removes all static resources served directly by the server.
|
void |
removeHttpAuthentication(String username)
Removes a user from all HTTP protected realms.
|
void |
removeHttpAuthentication(String username,
String realmName)
Removes a user to an HTTP protected realm.
|
void |
removeResponseHeader(Object exchange,
String name)
Removes a response header.
|
void |
removeStaticResourcesServed(StaticResourceType staticResourceType,
String urlPath)
Removes a static resource served directly by the server.
|
void |
setResponseHeader(Object exchange,
String name,
List<String> values)
Sets a response header.
|
void |
setResponseHeaders(Object exchange,
Map<String,List<String>> headers)
Sets the response headers.
|
void |
setResponseStatusCode(Object exchange,
int statusCode)
Sets the response status code.
|
void |
start()
Starts the server.
|
void |
stop()
Stops the server
|
void |
stop(boolean sendClosingMessageToPeers)
Stops the server
|
void |
websocketCloseEndpoint(String endpointId)
Closes a Websocket endpoint.
|
void |
websocketCloseEndpoint(String endpointId,
int closingCode,
String closingReason)
Closes the entire Websocket endpoint.
|
void |
websocketConnection(Object exchange,
String endpointId,
String peerId)
Transforms the request to a peer Websocket connection
on the endpoint 'endpointId'.
|
WebsocketEndpointManager |
websocketCreateEndpoint(String endpointId,
WebsocketEndpointHandler endpointHandler)
Creates a new Websocket endpoint.
|
void start()
void stop()
Will try to send a "closing" message to any WebSocket peer before closing their connections.
void stop(boolean sendClosingMessageToPeers)
sendClosingMessageToPeers - if true,
Spincast will try to send a "closing" message to any
WebSocket peer before closing their connections.boolean isRunning()
void addStaticResourceToServe(StaticResource<?> staticResource)
void removeStaticResourcesServed(StaticResourceType staticResourceType, String urlPath)
void removeAllStaticResourcesServed()
StaticResource<?> getStaticResourceServed(String urlPath)
Set<StaticResource<?>> getStaticResourcesServed()
HttpMethod getHttpMethod(Object exchange)
String getFullUrlOriginal(Object exchange)
This is going to be the *original* URL, as seen by the user, even if a reverse proxy is used (such as Nginx or Apache).
Even if the request is forwarded elsewhere in the framework, this URL won't change, it will still be the original one.
String getFullUrlOriginal(Object exchange, boolean keepCacheBusters)
This is going to be the *original* URL, as seen by the user, even if a reverse proxy is used (such as Nginx or Apache).
Even if the request is forwarded elsewhere in the framework, this URL won't change, it will still be the original one.
keepCacheBusters - if true, the returned URL will contain
the cache buster codes, if there were any. The default behavior is to
automatically remove them.String getFullUrlProxied(Object exchange)
Is a reverse proxy is used (such as Nginx or Apache), this is going to be the proxied URL, as forwarded by the reverse proxy. If no reverse proxy is used, this is going to be the original URL, as seen by the user.
Even if the request is forwarded elsewhere in the framework, this URL won't change, it will still be the original one.
String getFullUrlProxied(Object exchange, boolean keepCacheBusters)
Is a reverse proxy is used (such as Nginx or Apache), this is going to be the proxied URL, as forwarded by the reverse proxy. If no reverse proxy is used, this is going to be the original URL, as seen by the user.
Even if the request is forwarded elsewhere in the framework, this URL won't change, it will still be the original one.
keepCacheBusters - if true, the returned URL will contain
the cache buster codes, if there were any. The default behavior is to
automatically remove them.ContentTypeDefaults getContentTypeBestMatch(Object exchange)
Content-Type to use for the current request.void setResponseHeaders(Object exchange, Map<String,List<String>> headers)
void setResponseHeader(Object exchange, String name, List<String> values)
Map<String,List<String>> getResponseHeaders(Object exchange)
void removeResponseHeader(Object exchange, String name)
Map<String,List<String>> getQueryStringParams(Object exchange)
void setResponseStatusCode(Object exchange, int statusCode)
void flushBytes(Object exchange, byte[] bytes, boolean end)
end - if true, the exchange will be closed
and nothing more can be send.void end(Object exchange)
boolean isResponseClosed(Object exchange)
boolean isResponseHeadersSent(Object exchange)
String getRequestScheme(Object exchange)
InputStream getRawInputStream(Object exchange)
Map<String,List<File>> getUploadedFiles(Object exchange)
boolean forceRequestSizeValidation(Object exchange)
Map<String,List<String>> getRequestHeaders(Object exchange)
void createHttpAuthenticationRealm(String pathPrefix, String realmName)
realmName - The name of the realm. Must be unique on this server,
otherwise an exception is thrown. This allows the application to add
user to the realm using its name.Map<String,String> getHttpAuthenticationRealms()
The map is immutable.
void addHttpAuthentication(String realmName, String username, String password)
void removeHttpAuthentication(String username, String realmName)
void removeHttpAuthentication(String username)
WebsocketEndpointManager websocketCreateEndpoint(String endpointId, WebsocketEndpointHandler endpointHandler)
void websocketCloseEndpoint(String endpointId)
void websocketCloseEndpoint(String endpointId, int closingCode, String closingReason)
closingCode - The closing code.closingReason - The closing reason.void websocketConnection(Object exchange, String endpointId, String peerId)
List<WebsocketEndpointManager> getWebsocketEndpointManagers()
WebsocketEndpointManager getWebsocketEndpointManager(String endpointId)
null if not found.Copyright © 2017. All rights reserved.