Skip to content

Commit

Permalink
Avoid a header extraction exception
Browse files Browse the repository at this point in the history
Fix: #99
  • Loading branch information
io7m committed Dec 17, 2023
1 parent 2b35743 commit 3d58426
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import io.opentelemetry.context.propagation.TextMapGetter;

import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Objects;

/**
* A propagator that can extract fields from a servlet request.
Expand Down Expand Up @@ -51,6 +53,8 @@ private IdHTTPServerRequestContextExtractor()
public Iterable<String> keys(
final ServerRequest request)
{
Objects.requireNonNull(request, "request");

final var results =
new ArrayList<String>();
final var headers =
Expand All @@ -70,6 +74,18 @@ public String get(
final ServerRequest request,
final String name)
{
return request.headers().get(HeaderNames.create(name)).get();
Objects.requireNonNull(request, "request");
Objects.requireNonNull(name, "name");

final var headerName =
HeaderNames.create(name);
final var headers =
request.headers();

try {
return headers.get(headerName).get();
} catch (final NoSuchElementException e) {
return null;
}
}
}

0 comments on commit 3d58426

Please sign in to comment.