Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,8 @@ public String readAttribute(final RoutingContext exchange) {
httpMethod = exchange.request().method();
uri = exchange.request().uri();
}
StringBuilder sb = new StringBuilder()
.append(httpMethod)
.append(' ')
.append(uri);
sb.append(' ');
String httpVersion = "-";
switch (exchange.request().version()) {
case HTTP_1_0:
httpVersion = "HTTP/1.0";
break;
case HTTP_1_1:
httpVersion = "HTTP/1.1";
break;
case HTTP_2:
httpVersion = "HTTP/2";
break;
default:
// best effort to try and infer the HTTP version from
// any "unknown" enum value
httpVersion = exchange.request().version().name()
.replace("HTTP_", "HTTP/")
.replace("_", ".");
break;
}
sb.append(httpVersion);
return sb.toString();

return httpMethod + " " + uri + " " + RequestProtocolAttribute.getHttpVersionStr(exchange.request().version());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.vertx.http.runtime.attribute;

import io.vertx.core.http.HttpVersion;
import io.vertx.ext.web.RoutingContext;

/**
Expand All @@ -19,14 +20,30 @@ private RequestProtocolAttribute() {

@Override
public String readAttribute(final RoutingContext exchange) {
return exchange.request().version().name();
return getHttpVersionStr(exchange.request().version());
}

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

static String getHttpVersionStr(HttpVersion version) {
// best effort to try and infer the HTTP version from
// any "unknown" enum value
return switch (version) {
case HTTP_1_0 -> "HTTP/1.0";
case HTTP_1_1 -> "HTTP/1.1";
case HTTP_2 -> "HTTP/2";
default ->
// best effort to try and infer the HTTP version from
// any "unknown" enum value
version.name()
.replace("HTTP_", "HTTP/")
.replace("_", ".");
};
}

public static final class Builder implements ExchangeAttributeBuilder {

@Override
Expand Down
Loading