|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
27 | 27 | import io.netty.handler.codec.http.HttpHeaderNames;
|
28 | 28 | import io.netty.handler.codec.http.cookie.Cookie;
|
29 | 29 | import io.netty.handler.ssl.SslHandler;
|
| 30 | +import org.apache.commons.logging.Log; |
30 | 31 | import reactor.core.publisher.Flux;
|
31 | 32 | import reactor.netty.Connection;
|
32 | 33 | import reactor.netty.http.server.HttpServerRequest;
|
33 | 34 |
|
34 | 35 | import org.springframework.core.io.buffer.DataBuffer;
|
35 | 36 | import org.springframework.core.io.buffer.NettyDataBufferFactory;
|
36 | 37 | import org.springframework.http.HttpCookie;
|
| 38 | +import org.springframework.http.HttpLogging; |
37 | 39 | import org.springframework.lang.Nullable;
|
38 | 40 | import org.springframework.util.Assert;
|
| 41 | +import org.springframework.util.ClassUtils; |
39 | 42 | import org.springframework.util.LinkedMultiValueMap;
|
40 | 43 | import org.springframework.util.MultiValueMap;
|
41 | 44 |
|
|
48 | 51 | */
|
49 | 52 | class ReactorServerHttpRequest extends AbstractServerHttpRequest {
|
50 | 53 |
|
| 54 | + /** Reactor Netty 1.0.5+. */ |
| 55 | + static final boolean reactorNettyRequestChannelOperationsIdPresent = ClassUtils.isPresent( |
| 56 | + "reactor.netty.ChannelOperationsId", ReactorServerHttpRequest.class.getClassLoader()); |
| 57 | + |
| 58 | + private static final Log logger = HttpLogging.forLogName(ReactorServerHttpRequest.class); |
| 59 | + |
| 60 | + |
51 | 61 | private static final AtomicLong logPrefixIndex = new AtomicLong();
|
52 | 62 |
|
53 | 63 |
|
@@ -187,11 +197,28 @@ public <T> T getNativeRequest() {
|
187 | 197 | @Override
|
188 | 198 | @Nullable
|
189 | 199 | protected String initId() {
|
| 200 | + if (reactorNettyRequestChannelOperationsIdPresent) { |
| 201 | + return (ChannelOperationsIdHelper.getId(this.request)); |
| 202 | + } |
190 | 203 | if (this.request instanceof Connection) {
|
191 | 204 | return ((Connection) this.request).channel().id().asShortText() +
|
192 | 205 | "-" + logPrefixIndex.incrementAndGet();
|
193 | 206 | }
|
194 | 207 | return null;
|
195 | 208 | }
|
196 | 209 |
|
| 210 | + |
| 211 | + private static class ChannelOperationsIdHelper { |
| 212 | + |
| 213 | + @Nullable |
| 214 | + public static String getId(HttpServerRequest request) { |
| 215 | + if (request instanceof reactor.netty.ChannelOperationsId) { |
| 216 | + return (logger.isDebugEnabled() ? |
| 217 | + ((reactor.netty.ChannelOperationsId) request).asLongText() : |
| 218 | + ((reactor.netty.ChannelOperationsId) request).asShortText()); |
| 219 | + } |
| 220 | + return null; |
| 221 | + } |
| 222 | + } |
| 223 | + |
197 | 224 | }
|
0 commit comments