Skip to content

Commit 073d40d

Browse files
authored
Merge pull request quarkusio#48124 from geoand/quarkusio#48122
Follow the Common Log Format in access logs for HTTP version when 'H' is used
2 parents 66ea077 + f65d988 commit 073d40d

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/attribute/RequestLineAttribute.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,8 @@ public String readAttribute(final RoutingContext exchange) {
3838
httpMethod = exchange.request().method();
3939
uri = exchange.request().uri();
4040
}
41-
StringBuilder sb = new StringBuilder()
42-
.append(httpMethod)
43-
.append(' ')
44-
.append(uri);
45-
sb.append(' ');
46-
String httpVersion = "-";
47-
switch (exchange.request().version()) {
48-
case HTTP_1_0:
49-
httpVersion = "HTTP/1.0";
50-
break;
51-
case HTTP_1_1:
52-
httpVersion = "HTTP/1.1";
53-
break;
54-
case HTTP_2:
55-
httpVersion = "HTTP/2";
56-
break;
57-
default:
58-
// best effort to try and infer the HTTP version from
59-
// any "unknown" enum value
60-
httpVersion = exchange.request().version().name()
61-
.replace("HTTP_", "HTTP/")
62-
.replace("_", ".");
63-
break;
64-
}
65-
sb.append(httpVersion);
66-
return sb.toString();
41+
42+
return httpMethod + " " + uri + " " + RequestProtocolAttribute.getHttpVersionStr(exchange.request().version());
6743
}
6844

6945
@Override

extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/attribute/RequestProtocolAttribute.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.quarkus.vertx.http.runtime.attribute;
22

3+
import io.vertx.core.http.HttpVersion;
34
import io.vertx.ext.web.RoutingContext;
45

56
/**
@@ -19,14 +20,30 @@ private RequestProtocolAttribute() {
1920

2021
@Override
2122
public String readAttribute(final RoutingContext exchange) {
22-
return exchange.request().version().name();
23+
return getHttpVersionStr(exchange.request().version());
2324
}
2425

2526
@Override
2627
public void writeAttribute(final RoutingContext exchange, final String newValue) throws ReadOnlyAttributeException {
2728
throw new ReadOnlyAttributeException("Request getProtocol", newValue);
2829
}
2930

31+
static String getHttpVersionStr(HttpVersion version) {
32+
// best effort to try and infer the HTTP version from
33+
// any "unknown" enum value
34+
return switch (version) {
35+
case HTTP_1_0 -> "HTTP/1.0";
36+
case HTTP_1_1 -> "HTTP/1.1";
37+
case HTTP_2 -> "HTTP/2";
38+
default ->
39+
// best effort to try and infer the HTTP version from
40+
// any "unknown" enum value
41+
version.name()
42+
.replace("HTTP_", "HTTP/")
43+
.replace("_", ".");
44+
};
45+
}
46+
3047
public static final class Builder implements ExchangeAttributeBuilder {
3148

3249
@Override

0 commit comments

Comments
 (0)