Skip to content

Commit 34cb5df

Browse files
committed
Consistent id for ReactorServerHttpRequest
Closes gh-27885
1 parent 01231fe commit 34cb5df

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -218,9 +218,18 @@ public SslInfo getSslInfo() {
218218
*/
219219
String getLogPrefix() {
220220
if (this.logPrefix == null) {
221-
this.logPrefix = "[" + getId() + "] ";
221+
this.logPrefix = "[" + initLogPrefix() + "] ";
222222
}
223223
return this.logPrefix;
224224
}
225225

226+
/**
227+
* Subclasses can override this to provide the prefix to use for log messages.
228+
* <p>By default, this is {@link #getId()}.
229+
* @since 5.3.15
230+
*/
231+
protected String initLogPrefix() {
232+
return getId();
233+
}
234+
226235
}

spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -77,7 +77,7 @@ public ReactorServerHttpRequest(HttpServerRequest request, NettyDataBufferFactor
7777

7878
private static URI initUri(HttpServerRequest request) throws URISyntaxException {
7979
Assert.notNull(request, "HttpServerRequest must not be null");
80-
return new URI(resolveBaseUrl(request).toString() + resolveRequestUri(request));
80+
return new URI(resolveBaseUrl(request) + resolveRequestUri(request));
8181
}
8282

8383
private static URI resolveBaseUrl(HttpServerRequest request) throws URISyntaxException {
@@ -197,14 +197,26 @@ public <T> T getNativeRequest() {
197197
@Override
198198
@Nullable
199199
protected String initId() {
200+
if (this.request instanceof Connection) {
201+
return ((Connection) this.request).channel().id().asShortText() +
202+
"-" + logPrefixIndex.incrementAndGet();
203+
}
204+
return null;
205+
}
206+
207+
@Override
208+
protected String initLogPrefix() {
200209
if (reactorNettyRequestChannelOperationsIdPresent) {
201-
return (ChannelOperationsIdHelper.getId(this.request));
210+
String id = (ChannelOperationsIdHelper.getId(this.request));
211+
if (id != null) {
212+
return id;
213+
}
202214
}
203215
if (this.request instanceof Connection) {
204216
return ((Connection) this.request).channel().id().asShortText() +
205217
"-" + logPrefixIndex.incrementAndGet();
206218
}
207-
return null;
219+
return getId();
208220
}
209221

210222

0 commit comments

Comments
 (0)