Package io.mangoo.utils
Class RequestUtils
java.lang.Object
io.mangoo.utils.RequestUtils
- Author:
- svenkubiak
-
Method Summary
Modifier and TypeMethodDescriptionstatic io.undertow.util.AttachmentKey<Attachment>getRequestParameters(io.undertow.server.HttpServerExchange exchange) Converts request and query parameter into a single mapstatic StringgetServerSentEventURL(io.undertow.server.handlers.sse.ServerSentEventConnection connection) Retrieves a URL from a Server-Sent Event connectionstatic StringCreates and URL with only path and if present query and fragment, e.g.static StringgetWebSocketURL(io.undertow.websockets.core.WebSocketChannel channel) Retrieves the URL of a WebSocketChannelstatic booleanhasValidAuthentication(String cookie) Checks if the given header contains a valid authenticationstatic booleanisJsonRequest(io.undertow.server.HttpServerExchange exchange) Checks if the requests content-type contains application/jsonstatic booleanisPostPutPatch(io.undertow.server.HttpServerExchange exchange) Checks if the request is a POST, PUT or PATCH requeststatic io.undertow.server.HttpHandlerwrapBasicAuthentication(io.undertow.server.HttpHandler httpHandler, String username, String password) Adds a Wrapper to the handler when the request requires authentication
-
Method Details
-
getAttachmentKey
-
getRequestParameters
public static Map<String,String> getRequestParameters(io.undertow.server.HttpServerExchange exchange) Converts request and query parameter into a single map- Parameters:
exchange- The Undertow HttpServerExchange- Returns:
- A single map contain both request and query parameter
-
isPostPutPatch
public static boolean isPostPutPatch(io.undertow.server.HttpServerExchange exchange) Checks if the request is a POST, PUT or PATCH request- Parameters:
exchange- The Undertow HttpServerExchange- Returns:
- True if the request is a POST, PUT or PATCH request, false otherwise
-
isJsonRequest
public static boolean isJsonRequest(io.undertow.server.HttpServerExchange exchange) Checks if the requests content-type contains application/json- Parameters:
exchange- The Undertow HttpServerExchange- Returns:
- True if the request content-type contains application/json, false otherwise
-
hasValidAuthentication
Checks if the given header contains a valid authentication- Parameters:
cookie- The cookie to parse- Returns:
- True if the cookie contains a valid authentication, false otherwise
-
getServerSentEventURL
public static String getServerSentEventURL(io.undertow.server.handlers.sse.ServerSentEventConnection connection) Retrieves a URL from a Server-Sent Event connection- Parameters:
connection- The ServerSentEvent Connection- Returns:
- The URL of the Server-Sent Event Connection
-
getWebSocketURL
Retrieves the URL of a WebSocketChannel- Parameters:
channel- The WebSocket Channel- Returns:
- The URL of the WebSocket Channel
-
getURL
Creates and URL with only path and if present query and fragment, e.g. /path/data?key=value#fragid1- Parameters:
uri- The URI to generate from- Returns:
- The generated URL
-
wrapBasicAuthentication
public static io.undertow.server.HttpHandler wrapBasicAuthentication(io.undertow.server.HttpHandler httpHandler, String username, String password) Adds a Wrapper to the handler when the request requires authentication- Parameters:
httpHandler- The Handler to wrapusername- The username to usepassword- The password to use- Returns:
- An HttpHandler wrapped through BasicAuthentication
-