/** * Accepts only requests with one of specified HTTP methods. * * @param methods Acceptable method names * @return composed predicate representing the logical expression between * this predicate <b>AND</b> the provided predicate * @throws NullPointerException if the methods type array is null */ public RequestPredicate isOfMethod(final Method... methods) { Objects.requireNonNull(methods, "methods"); return and((req) -> Stream.of(methods) .map(Method::name) .anyMatch(req.method().name()::equals)); }
ContainerRequest requestContext = new ContainerRequest(baseUri(req), requestUri(req), req.method().name(), new WebServerSecurityContext(), new WebServerPropertiesDelegate(req));
private void registerContext(ServerRequest req, ServerResponse res) { Map<String, List<String>> allHeaders = new HashMap<>(req.headers().toMap()); Optional<Map> newHeaders = req.context().get(CONTEXT_ADD_HEADERS, Map.class); newHeaders.ifPresent(allHeaders::putAll); //make sure there is no context if (!req.context().get(SecurityContext.class).isPresent()) { SecurityEnvironment env = security.environmentBuilder() .targetUri(req.uri()) .path(req.path().toString()) .method(req.method().name()) .addAttribute("userIp", req.remoteAddress()) .addAttribute("userPort", req.remotePort()) .transport(req.isSecure() ? "https" : "http") .headers(allHeaders) .build(); EndpointConfig ec = EndpointConfig.builder() .build(); SecurityContext context = security.contextBuilder(String.valueOf(SECURITY_COUNTER.incrementAndGet())) .tracingSpan(req.spanContext()) .env(env) .endpointConfig(ec) .build(); req.context().register(context); req.context().register(defaultHandler); } req.next(); }
@Override public Http.RequestMethod getMethod() { return Http.RequestMethod.from(nettyRequest.method().name()); }
ContainerRequest requestContext = new ContainerRequest(baseUri(req), requestUri(req), req.method().name(), new WebServerSecurityContext(), new WebServerPropertiesDelegate(req));
private void registerContext(ServerRequest req, ServerResponse res) { Map<String, List<String>> allHeaders = new HashMap<>(req.headers().toMap()); Optional<Map> newHeaders = req.context().get(CONTEXT_ADD_HEADERS, Map.class); newHeaders.ifPresent(allHeaders::putAll); //make sure there is no context if (!req.context().get(SecurityContext.class).isPresent()) { SecurityEnvironment env = security.environmentBuilder() .targetUri(req.uri()) .path(req.path().toString()) .method(req.method().name()) .addAttribute("userIp", req.remoteAddress()) .addAttribute("userPort", req.remotePort()) .transport(req.isSecure() ? "https" : "http") .headers(allHeaders) .build(); EndpointConfig ec = EndpointConfig.builder() .build(); SecurityContext context = security.contextBuilder(String.valueOf(SECURITY_COUNTER.incrementAndGet())) .tracingSpan(req.spanContext()) .env(env) .endpointConfig(ec) .build(); req.context().register(context); req.context().register(defaultHandler); } req.next(); }
/** * Accepts only requests with one of specified HTTP methods. * * @param methods Acceptable method names * @return composed predicate representing the logical expression between * this predicate <b>AND</b> the provided predicate * @throws NullPointerException if the specified methods array is null */ public RequestPredicate isOfMethod(final String... methods) { Objects.requireNonNull(methods, "methods"); return and((req) -> Stream.of(methods) .map(String::toUpperCase) .anyMatch(req.method().name()::equals)); }
private Span createRequestSpan(Tracer tracer, BareRequest request) { Tracer.SpanBuilder spanBuilder = tracer.buildSpan("HTTP Request") .withTag(Tags.COMPONENT.getKey(), "helidon-webserver") .withTag(Tags.HTTP_METHOD.getKey(), request.method().name()) .withTag(Tags.HTTP_URL.getKey(), request.uri().toString()); Map<String, String> headersMap = request.headers() .entrySet() .stream() .filter(entry -> !entry.getValue().isEmpty()) .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get(0))); SpanContext spanContext = tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(headersMap)); if (spanContext != null) { spanBuilder.asChildOf(spanContext); } return spanBuilder.start(); }
@Override public Http.RequestMethod method() { return Http.RequestMethod.create(nettyRequest.method().name()); }
@Override public boolean equals(Object other) { return (other instanceof RequestMethod) && name().equals(((RequestMethod) other).name()); }