From d2e278dccea1b2ffae85d010c213804ffc65011a Mon Sep 17 00:00:00 2001 From: asahi Date: Mon, 10 Mar 2025 20:50:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=85=E8=AF=BB=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring/webflux/spring webflux.md | 96 ++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/spring/webflux/spring webflux.md b/spring/webflux/spring webflux.md index fd139bd..1b9e3cd 100644 --- a/spring/webflux/spring webflux.md +++ b/spring/webflux/spring webflux.md @@ -178,5 +178,101 @@ server.start(); ### WebHandler API `org.springframework.web.server` package基于`HttpHandler`构建,提供了通用的Web API。Web Api由多个`WebException`, 多个`WebFilter`, 一个`WebHandler`组件构成,组成了一个chain。 +相比于`HttpHandler`仅仅是对不同http server的抽象,`WebHandler`提供了一个更加通用、更加广泛的功能集合: +- user sessions attributes +- request attributes +- resolved `Locale` or `Principal` for request +- abstractions for multipart data +#### bean types for WebHttpHandlerBuilder auto-detect +在spring上下文中,`WebHttpHandlerBuilder`可以自动探测到如下类型的components: + ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Bean nameBean typeCountDescription

<any>

WebExceptionHandler

0..N

Provide handling for exceptions from the chain of WebFilter instances and the target + WebHandler. For more details, see Exceptions.

<any>

WebFilter

0..N

Apply interception style logic to before and after the rest of the filter chain and + the target WebHandler. For more details, see Filters.

webHandler

WebHandler

1

The handler for the request.

webSessionManager

WebSessionManager

0..1

The manager for WebSession instances exposed through a method on ServerWebExchange. + DefaultWebSessionManager by default.

serverCodecConfigurer

ServerCodecConfigurer

0..1

For access to HttpMessageReader instances for parsing form data and multipart data that is then + exposed through methods on ServerWebExchange. ServerCodecConfigurer.create() by default.

localeContextResolver

LocaleContextResolver

0..1

The resolver for LocaleContext exposed through a method on ServerWebExchange. + AcceptHeaderLocaleContextResolver by default.

forwardedHeaderTransformer

ForwardedHeaderTransformer

0..1

For processing forwarded type headers, either by extracting and removing them or by removing them only. + Not used by default.

+#### Form Data +`ServerWebExchange`将会向外暴露如下方法,用于访问form data: +```java +Mono> getFormData(); +``` +`DefaultServerWebExchange`使用`HttpMessageReader`来对form data(application/x-www-form-urlencoded)进行parse操作,将formdata转化为`MultiValueMap`。 + +#### Multipart Data +`ServerWebExchange`向外暴露如下方法,用于访问multipart data。 + +```java +Mono> getMultipartData(); +``` + +`DefaultServerWebExchange`将会使用`HttpMessageReader>`来对`multipart/form-data`,`multipart/mixed`,`multipart/related`数据进行转换,数据将会被转化为`MultiValueMap`类型。 + +#### Filter +在`WebHandler API`中,可以使用`WebFilter`来实现拦截式的逻辑,当使用`Webflux Config`时,`WebFilter`的注可以通过将其注册为bean来实现。 + +对于`WebFilter`的优先级,欸可以通过使用`@Order`注解或实现`Ordered`接口来实现。 + +#### CORS +spring webflux支持通过@CORSLAI1 \ No newline at end of file