use of io.micronaut.http.HttpHeaders in project micronaut-core by micronaut-projects.
the class HttpRequestTest method testForEach2.
public void testForEach2() {
final DefaultFullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, io.netty.handler.codec.http.HttpMethod.GET, "/test");
nettyRequest.headers().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
nettyRequest.headers().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML);
HttpRequest<?> request = new NettyHttpRequest(nettyRequest, new DetachedMockFactory().Mock(ChannelHandlerContext.class), ConversionService.SHARED, new HttpServerConfiguration());
final HttpHeaders headers = request.getHeaders();
headers.forEach((name, values) -> {
assertEquals(HttpHeaders.CONTENT_TYPE, name);
assertEquals(2, values.size());
assertTrue(values.contains(MediaType.APPLICATION_JSON));
assertTrue(values.contains(MediaType.APPLICATION_XML));
});
AtomicInteger integer = new AtomicInteger(0);
headers.forEachValue((s, s2) -> integer.incrementAndGet());
assertEquals(2, integer.get());
}
use of io.micronaut.http.HttpHeaders in project micronaut-core by micronaut-projects.
the class CorsFilter method handleResponse.
/**
* Handles a CORS response.
*
* @param request The {@link HttpRequest} object
* @param response The {@link MutableHttpResponse} object
*/
protected void handleResponse(HttpRequest<?> request, MutableHttpResponse<?> response) {
HttpHeaders headers = request.getHeaders();
Optional<String> originHeader = headers.getOrigin();
originHeader.ifPresent(requestOrigin -> {
Optional<CorsOriginConfiguration> optionalConfig = getConfiguration(requestOrigin);
if (optionalConfig.isPresent()) {
CorsOriginConfiguration config = optionalConfig.get();
if (CorsUtil.isPreflightRequest(request)) {
Optional<HttpMethod> result = headers.getFirst(ACCESS_CONTROL_REQUEST_METHOD, CONVERSION_CONTEXT_HTTP_METHOD);
setAllowMethods(result.get(), response);
Optional<List<String>> allowedHeaders = headers.get(ACCESS_CONTROL_REQUEST_HEADERS, ConversionContext.LIST_OF_STRING);
allowedHeaders.ifPresent(val -> setAllowHeaders(val, response));
setMaxAge(config.getMaxAge(), response);
}
setOrigin(requestOrigin, response);
setVary(response);
setExposeHeaders(config.getExposedHeaders(), response);
setAllowCredentials(config, response);
}
});
}
use of io.micronaut.http.HttpHeaders in project micronaut-security by micronaut-projects.
the class ClientCredentialsHeaderTokenPropagator method findToken.
/**
* Search for a JWT token in a HTTP request.
* @param request The request to look for the token in
* @return if the JWT token is found it is returned, empty if not
*/
@Override
public Optional<String> findToken(@NonNull HttpRequest<?> request) {
HttpHeaders headers = request.getHeaders();
Optional<String> authorizationHeader = headers.findFirst(configuration.getHeaderName());
return authorizationHeader.flatMap(this::extractTokenFromAuthorization);
}
use of io.micronaut.http.HttpHeaders in project micronaut-security by micronaut-projects.
the class HttpHeaderTokenPropagator method findToken.
/**
* Search for a JWT token in a HTTP request.
* @param request The request to look for the token in
* @return if the JWT token is found it is returned, empty if not
*/
@Override
public Optional<String> findToken(HttpRequest<?> request) {
HttpHeaders headers = request.getHeaders();
Optional<String> authorizationHeader = headers.findFirst(configuration.getHeaderName());
return authorizationHeader.flatMap(this::extractTokenFromAuthorization);
}
use of io.micronaut.http.HttpHeaders in project micronaut-security by micronaut-projects.
the class HttpHeaderTokenReader method findToken.
/**
* Search for a JWT token in a HTTP request.
* @param request The request to look for the token in
* @return if the JWT token is found it is returned, empty if not
*/
@Override
public Optional<String> findToken(HttpRequest<?> request) {
if (LOG.isDebugEnabled()) {
LOG.debug("Looking for bearer token in {} header", getHeaderName());
}
HttpHeaders headers = request.getHeaders();
Optional<String> authorizationHeader = headers.findFirst(getHeaderName());
return authorizationHeader.flatMap(this::extractTokenFromAuthorization);
}
Aggregations