Skip to content

io microsphere spring web util WebRequestUtils

github-actions[bot] edited this page Jun 18, 2026 · 18 revisions

WebRequestUtils

Type: Class | Module: microsphere-spring-web | Package: io.microsphere.spring.web.util | Since: 1.0.0

Source: microsphere-spring-web/src/main/java/io/microsphere/spring/web/util/WebRequestUtils.java

Overview

WebRequest Utilities class

Declaration

public abstract class WebRequestUtils

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.27-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-spring-web</artifactId>
    <version>${microsphere-spring.version}</version>
</dependency>

Tip: Use the BOM (microsphere-spring-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.spring.web.util.WebRequestUtils;

API Reference

Public Methods

Method Description
getMethod The header name for HTTP method
isPreFlightRequest Returns true if the request is a valid CORS pre-flight one by checking OPTIONS method with
getContentType
parseContentType
hasBody
getResolvedLookupPath Return a previously UrlPathHelper#getLookupPathForRequest resolved lookupPath.
getHeader Get the header value from the request by the given header name.
getHeaderValues Get the header values from the request by the given header name.
setHeader Sets a response header with the given name and value. If the header had already been set,
addHeader Adds a response header with the given name and value. This method allows response headers to have multiple values.
getCookieValue Get the cookie value for the given cookie name.
addCookie Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.
getRequestBody
writeResponseBody Write value to the response body.
getBestMatchingHandler Get the mapped handler for the best matching pattern.
getPathWithinHandlerMapping Get the path within the handler mapping, in case of a pattern match, or the full relevant URI
getBestMatchingPattern Get the best matching pattern within the handler mapping.
getProducibleMediaTypes Get the URI templates map, mapping variable names to values.

Method Details

getMethod

public static String getMethod(@Nonnull NativeWebRequest request)

The header name for HTTP method / public static final String METHOD_HEADER_NAME = ":METHOD:";

/** Name of Servlet request attribute that holds a UrlPathHelper#getLookupPathForRequest resolved lookupPath.

Since: Spring Framework 5.3

isPreFlightRequest

public static boolean isPreFlightRequest(@Nonnull NativeWebRequest request)

Returns true if the request is a valid CORS pre-flight one by checking OPTIONS method with Origin and Access-Control-Request-Method headers presence.

getResolvedLookupPath

public static String getResolvedLookupPath(@Nonnull NativeWebRequest request)

Return a previously UrlPathHelper#getLookupPathForRequest resolved lookupPath.

getHeader

public static String getHeader(@Nonnull NativeWebRequest request, String headerName)

Get the header value from the request by the given header name.

getHeaderValues

public static String[] getHeaderValues(@Nonnull NativeWebRequest request, String headerName)

Get the header values from the request by the given header name.

setHeader

public static void setHeader(@Nonnull NativeWebRequest request, @Nullable String headerName, @Nullable String headerValue)

Sets a response header with the given name and value. If the header had already been set, the new value overwrites all previous values.

addHeader

public static void addHeader(@Nonnull NativeWebRequest request, @Nullable String headerName, @Nullable String... headerValues)

Adds a response header with the given name and value. This method allows response headers to have multiple values.

addCookie

public static void addCookie(@Nonnull NativeWebRequest request, String cookieName, String cookieValue)

Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.

getBestMatchingHandler

public static Object getBestMatchingHandler(@Nonnull NativeWebRequest request)

Get the mapped handler for the best matching pattern.

getPathWithinHandlerMapping

public static String getPathWithinHandlerMapping(@Nonnull NativeWebRequest request)

Get the path within the handler mapping, in case of a pattern match, or the full relevant URI (typically within the DispatcherServlet's mapping) else.

getBestMatchingPattern

public static String getBestMatchingPattern(@Nonnull NativeWebRequest request)

Get the best matching pattern within the handler mapping.

getProducibleMediaTypes

public static Set<MediaType> getProducibleMediaTypes(@Nonnull NativeWebRequest request)

Get the URI templates map, mapping variable names to values.


This documentation was auto-generated from the source code of microsphere-spring.

Home

spring-context

spring-guice

spring-jdbc

spring-test

spring-web

spring-webflux

spring-webmvc

Clone this wiki locally