Skip to content

Commit db50b6e

Browse files
committed
Polish RequestLineAttribute
1 parent 0abd32f commit db50b6e

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

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

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.quarkus.vertx.http.runtime.filters.OriginalRequestContext;
44
import io.vertx.core.http.HttpMethod;
5+
import io.vertx.core.http.HttpVersion;
56
import io.vertx.ext.web.RoutingContext;
67

78
/**
@@ -38,32 +39,24 @@ public String readAttribute(final RoutingContext exchange) {
3839
httpMethod = exchange.request().method();
3940
uri = exchange.request().uri();
4041
}
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:
42+
43+
return httpMethod + " " + uri + " " + getHttpVersionStr(exchange.request().version());
44+
}
45+
46+
private static String getHttpVersionStr(HttpVersion version) {
47+
// best effort to try and infer the HTTP version from
48+
// any "unknown" enum value
49+
return switch (version) {
50+
case HTTP_1_0 -> "HTTP/1.0";
51+
case HTTP_1_1 -> "HTTP/1.1";
52+
case HTTP_2 -> "HTTP/2";
53+
default ->
5854
// best effort to try and infer the HTTP version from
5955
// 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();
56+
version.name()
57+
.replace("HTTP_", "HTTP/")
58+
.replace("_", ".");
59+
};
6760
}
6861

6962
@Override

0 commit comments

Comments
 (0)