From f2244ee531440520bc1e6847ae2790efe5a42cfc Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Tue, 12 May 2020 08:34:45 +1000 Subject: [PATCH] Handle requests when the host header is not specified at all correctly. (#901) Signed-off-by: Adrian Sutton --- .../besu/metrics/prometheus/MetricsHttpService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/MetricsHttpService.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/MetricsHttpService.java index d9202d1dd7..06d32ca21b 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/MetricsHttpService.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/MetricsHttpService.java @@ -149,7 +149,11 @@ class MetricsHttpService implements MetricsService { } private Optional getAndValidateHostHeader(final RoutingContext event) { - final Iterable splitHostHeader = Splitter.on(':').split(event.request().host()); + final String hostHeader = event.request().host(); + if (hostHeader == null) { + return Optional.empty(); + } + final Iterable splitHostHeader = Splitter.on(':').split(hostHeader); final long hostPieces = stream(splitHostHeader).count(); if (hostPieces > 1) { // If the host contains a colon, verify the host is correctly formed - host [ ":" port ]