Package io.mangoo.utils
Class RequestUtils
- java.lang.Object
-
- io.mangoo.utils.RequestUtils
-
public final class RequestUtils extends Object
- Author:
- svenkubiak
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static io.undertow.util.AttachmentKey<Attachment>getAttachmentKey()static StringgetOperation(io.undertow.util.HttpString method)Return if a given HTTP method results in a read or write request to a resource GET = read POST = write PUT = write DELETE = write PATCH = write OPTIONS = read HEAD = readstatic Map<String,String>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 StringgetURL(URI uri)Creates 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 Detail
-
getAttachmentKey
public static io.undertow.util.AttachmentKey<Attachment> 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
public static boolean hasValidAuthentication(String cookie)
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
public static String getWebSocketURL(io.undertow.websockets.core.WebSocketChannel channel)
Retrieves the URL of a WebSocketChannel- Parameters:
channel- The WebSocket Channel- Returns:
- The URL of the WebSocket Channel
-
getURL
public static String getURL(URI uri)
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
-
getOperation
public static String getOperation(io.undertow.util.HttpString method)
Return if a given HTTP method results in a read or write request to a resource GET = read POST = write PUT = write DELETE = write PATCH = write OPTIONS = read HEAD = read- Parameters:
method- The HTTP method- Returns:
- read or write if HTTP method is found, blank otherwise
-
-