-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webflux): enhance command message parsing with customizable head…
…er appender (#1110) - Introduce CommandRequestHeaderAppender interface for flexible header handling - Implement CommandRequestExtendHeaderAppender for extended headers - Update DefaultCommandMessageParser to use CommandRequestHeaderAppender - Add commandRequestExtendHeaderAppender bean in WebFluxAutoConfiguration - Modify commandMessageParser bean to accept CommandRequestHeaderAppender
- Loading branch information
Showing
4 changed files
with
70 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...webflux/src/main/kotlin/me/ahoo/wow/webflux/route/command/CommandRequestHeaderAppender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright [2021-present] [ahoo wang <[email protected]> (https://github.com/Ahoo-Wang)]. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package me.ahoo.wow.webflux.route.command | ||
|
||
import me.ahoo.wow.command.factory.CommandBuilder | ||
import me.ahoo.wow.openapi.command.CommandRequestHeaders.COMMAND_HEADER_X_PREFIX | ||
import org.springframework.web.reactive.function.server.ServerRequest | ||
|
||
interface CommandRequestHeaderAppender { | ||
fun append(request: ServerRequest, commandBuilder: CommandBuilder) | ||
} | ||
|
||
object CommandRequestExtendHeaderAppender : CommandRequestHeaderAppender { | ||
override fun append(request: ServerRequest, commandBuilder: CommandBuilder) { | ||
val extendedHeaders = request.headers().asHttpHeaders() | ||
.filter { (key, _) -> key.startsWith(COMMAND_HEADER_X_PREFIX) } | ||
.map { (key, value) -> | ||
key.substring(COMMAND_HEADER_X_PREFIX.length) to value.firstOrNull<String>().orEmpty() | ||
}.toMap<String, String>() | ||
if (extendedHeaders.isEmpty()) { | ||
return | ||
} | ||
commandBuilder.header { header -> | ||
header.with(extendedHeaders) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters