@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2020 the original author or authors .
* Copyright 2002 - 2021 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -27,6 +27,7 @@ import io.netty.channel.Channel;
@@ -27,6 +27,7 @@ import io.netty.channel.Channel;
import io.netty.handler.codec.http.HttpHeaderNames ;
import io.netty.handler.codec.http.cookie.Cookie ;
import io.netty.handler.ssl.SslHandler ;
import org.apache.commons.logging.Log ;
import reactor.core.publisher.Flux ;
import reactor.netty.Connection ;
import reactor.netty.http.server.HttpServerRequest ;
@ -34,8 +35,10 @@ import reactor.netty.http.server.HttpServerRequest;
@@ -34,8 +35,10 @@ import reactor.netty.http.server.HttpServerRequest;
import org.springframework.core.io.buffer.DataBuffer ;
import org.springframework.core.io.buffer.NettyDataBufferFactory ;
import org.springframework.http.HttpCookie ;
import org.springframework.http.HttpLogging ;
import org.springframework.lang.Nullable ;
import org.springframework.util.Assert ;
import org.springframework.util.ClassUtils ;
import org.springframework.util.LinkedMultiValueMap ;
import org.springframework.util.MultiValueMap ;
@ -48,6 +51,13 @@ import org.springframework.util.MultiValueMap;
@@ -48,6 +51,13 @@ import org.springframework.util.MultiValueMap;
* /
class ReactorServerHttpRequest extends AbstractServerHttpRequest {
/** Reactor Netty 1.0.5+. */
static final boolean reactorNettyRequestChannelOperationsIdPresent = ClassUtils . isPresent (
"reactor.netty.ChannelOperationsId" , ReactorServerHttpRequest . class . getClassLoader ( ) ) ;
private static final Log logger = HttpLogging . forLogName ( ReactorServerHttpRequest . class ) ;
private static final AtomicLong logPrefixIndex = new AtomicLong ( ) ;
@ -187,6 +197,9 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest {
@@ -187,6 +197,9 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest {
@Override
@Nullable
protected String initId ( ) {
if ( reactorNettyRequestChannelOperationsIdPresent ) {
return ( ChannelOperationsIdHelper . getId ( this . request ) ) ;
}
if ( this . request instanceof Connection ) {
return ( ( Connection ) this . request ) . channel ( ) . id ( ) . asShortText ( ) +
"-" + logPrefixIndex . incrementAndGet ( ) ;
@ -194,4 +207,18 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest {
@@ -194,4 +207,18 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest {
return null ;
}
private static class ChannelOperationsIdHelper {
@Nullable
public static String getId ( HttpServerRequest request ) {
if ( request instanceof reactor . netty . ChannelOperationsId ) {
return ( logger . isDebugEnabled ( ) ?
( ( reactor . netty . ChannelOperationsId ) request ) . asLongText ( ) :
( ( reactor . netty . ChannelOperationsId ) request ) . asShortText ( ) ) ;
}
return null ;
}
}
}