Last active
March 23, 2021 04:10
-
-
Save wickedev/88ef9365c7f648b2c2ddb8ffe94eb78a to your computer and use it in GitHub Desktop.
webflux reactor API vs webflux kotlin coroutine
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
// Before Coroutine | |
fun matches(exchange: ServerWebExchange): Mono<MatchResult> { | |
return Mono.just(exchange) | |
.map(ServerWebExchange::getRequest) | |
.map(ServerHttpRequest::getHeaders) | |
.filter { header -> header.containsKey(HttpHeaders.AUTHORIZATION)) } | |
.flatMap { MatchResult.match() } | |
.switchIfEmpty { MatchResult.notMatch() } | |
} | |
// After Coroutine | |
fun matches(exchange: ServerWebExchange): Mono<MatchResult> = mono { | |
val request = exchange.request | |
val header = request.headers | |
if (header.containsKey(HttpHeaders.AUTHORIZATION)) { | |
return@mono MatchResult.match().await() | |
} | |
return@mono MatchResult.notMatch().await() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment