org.springframework.http.HttpHeaders.get()

Here are the examples of the java api org.springframework.http.HttpHeaders.get() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

146 Examples 7

19 View Source File : GrayHttpTrackInfo.java
License : Apache License 2.0
Project Creator : SpringCloud

public List<String> getHeader(String name) {
    return headers.get(name.toLowerCase());
}

18 View Source File : XXssProtectionHttpHeadersWriterTests.java
License : Apache License 2.0
Project Creator : spring-projects

@Test
public void writeHeadersWhenNoHeadersThenWriteHeaders() {
    writer.writeHttpHeaders(exchange);
    replacedertThat(headers).hreplacedize(1);
    replacedertThat(headers.get(XXssProtectionHttpHeadersWriter.X_XSS_PROTECTION)).containsOnly("1 ; mode=block");
}

18 View Source File : XXssProtectionHttpHeadersWriterTests.java
License : Apache License 2.0
Project Creator : spring-projects

@Test
public void writeHeadersWhenBlockFalseThenWriteHeaders() {
    writer.setBlock(false);
    writer.writeHttpHeaders(exchange);
    replacedertThat(headers).hreplacedize(1);
    replacedertThat(headers.get(XXssProtectionHttpHeadersWriter.X_XSS_PROTECTION)).containsOnly("1");
}

18 View Source File : XXssProtectionHttpHeadersWriterTests.java
License : Apache License 2.0
Project Creator : spring-projects

@Test
public void writeHeadersWhenHeaderWrittenThenDoesNotOverrride() {
    String headerValue = "value";
    headers.set(XXssProtectionHttpHeadersWriter.X_XSS_PROTECTION, headerValue);
    writer.writeHttpHeaders(exchange);
    replacedertThat(headers).hreplacedize(1);
    replacedertThat(headers.get(XXssProtectionHttpHeadersWriter.X_XSS_PROTECTION)).containsOnly(headerValue);
}

18 View Source File : XXssProtectionHttpHeadersWriterTests.java
License : Apache License 2.0
Project Creator : spring-projects

@Test
public void writeHeadersWhenEnabledFalseThenWriteHeaders() {
    writer.setEnabled(false);
    writer.writeHttpHeaders(exchange);
    replacedertThat(headers).hreplacedize(1);
    replacedertThat(headers.get(XXssProtectionHttpHeadersWriter.X_XSS_PROTECTION)).containsOnly("0");
}

18 View Source File : XContentTypeOptionsHttpHeadersWriterTests.java
License : Apache License 2.0
Project Creator : spring-projects

@Test
public void writeHeadersWhenHeaderWrittenThenDoesNotOverrride() {
    String headerValue = "value";
    headers.set(ContentTypeOptionsHttpHeadersWriter.X_CONTENT_OPTIONS, headerValue);
    writer.writeHttpHeaders(exchange);
    replacedertThat(headers).hreplacedize(1);
    replacedertThat(headers.get(ContentTypeOptionsHttpHeadersWriter.X_CONTENT_OPTIONS)).containsOnly(headerValue);
}

18 View Source File : XContentTypeOptionsHttpHeadersWriterTests.java
License : Apache License 2.0
Project Creator : spring-projects

@Test
public void writeHeadersWhenNoHeadersThenWriteHeaders() {
    writer.writeHttpHeaders(exchange);
    replacedertThat(headers).hreplacedize(1);
    replacedertThat(headers.get(ContentTypeOptionsHttpHeadersWriter.X_CONTENT_OPTIONS)).containsOnly(ContentTypeOptionsHttpHeadersWriter.NOSNIFF);
}

18 View Source File : StaticHttpHeadersWriterTests.java
License : Apache License 2.0
Project Creator : spring-projects

@Test
public void writeHeadersWhenSingleHeaderThenWritesHeader() {
    writer.writeHttpHeaders(exchange);
    replacedertThat(headers.get(ContentTypeOptionsHttpHeadersWriter.X_CONTENT_OPTIONS)).containsOnly(ContentTypeOptionsHttpHeadersWriter.NOSNIFF);
}

18 View Source File : StaticHttpHeadersWriterTests.java
License : Apache License 2.0
Project Creator : spring-projects

@Test
public void writeHeadersWhenSingleHeaderAndHeaderWrittenThenSuccess() {
    String headerValue = "other";
    headers.set(ContentTypeOptionsHttpHeadersWriter.X_CONTENT_OPTIONS, headerValue);
    writer.writeHttpHeaders(exchange);
    replacedertThat(headers.get(ContentTypeOptionsHttpHeadersWriter.X_CONTENT_OPTIONS)).containsOnly(headerValue);
}

18 View Source File : CacheControlHttpHeadersWriterTests.java
License : Apache License 2.0
Project Creator : spring-projects

@Test
public void writeHeadersWhenExpiresThenNoCacheControlHeaders() {
    String expires = "1";
    headers.set(HttpHeaders.EXPIRES, expires);
    writer.writeHttpHeaders(exchange);
    replacedertThat(headers).hreplacedize(1);
    replacedertThat(headers.get(HttpHeaders.EXPIRES)).containsOnly(expires);
}

18 View Source File : CacheControlHttpHeadersWriterTests.java
License : Apache License 2.0
Project Creator : spring-projects

@Test
public void writeHeadersWhenPragmaThenNoCacheControlHeaders() {
    String pragma = "1";
    headers.set(HttpHeaders.PRAGMA, pragma);
    writer.writeHttpHeaders(exchange);
    replacedertThat(headers).hreplacedize(1);
    replacedertThat(headers.get(HttpHeaders.PRAGMA)).containsOnly(pragma);
}

18 View Source File : ProxyExchange.java
License : Apache License 2.0
Project Creator : spring-cloud

private BodyBuilder headers(BodyBuilder builder) {
    proxy();
    for (String name : filterHeaderKeys(headers)) {
        builder.header(name, headers.get(name).toArray(new String[0]));
    }
    return builder;
}

18 View Source File : WebSocketPlugin.java
License : Apache License 2.0
Project Creator : dromara

private List<String> buildWsProtocols(final HttpHeaders headers) {
    List<String> protocols = headers.get(SEC_WEB_SOCKET_PROTOCOL);
    if (CollectionUtils.isNotEmpty(protocols)) {
        protocols = protocols.stream().flatMap(header -> Arrays.stream(StringUtils.commaDelimitedListToStringArray(header))).map(String::trim).collect(Collectors.toList());
    }
    return protocols;
}

18 View Source File : BlueOceanService.java
License : Apache License 2.0
Project Creator : doporg

// 获得authorization
public String getAuthorization() {
    String uri = "http://jenkins.dop.clsaa.com:8088/jwt-auth/token";
    HttpHeaders headers = restTemplate.getForEnreplacedy(uri, String.clreplaced).getHeaders();
    return headers.get("X-BLUEOCEAN-JWT").get(0);
}

18 View Source File : RequestMetadata.java
License : Apache License 2.0
Project Creator : alibaba

private static void mediaTypes(HttpHeaders httpHeaders, String headerName, Collection<String> destination) {
    List<String> value = httpHeaders.get(headerName);
    List<MediaType> mediaTypes = parseMediaTypes(value);
    destination.addAll(toMediaTypeValues(mediaTypes));
}

18 View Source File : HttpUtils.java
License : GNU Affero General Public License v3.0
Project Creator : agnitas-org

public static boolean isAjax(HttpHeaders headers) {
    List<String> values = headers.get("X-Requested-With");
    if (CollectionUtils.isEmpty(values)) {
        return false;
    }
    return values.contains("XMLHttpRequest");
}

17 View Source File : SockJsClient.java
License : MIT License
Project Creator : Vip-Augus

@Nullable
private HttpHeaders getHttpRequestHeaders(@Nullable HttpHeaders webSocketHttpHeaders) {
    if (getHttpHeaderNames() == null || webSocketHttpHeaders == null) {
        return webSocketHttpHeaders;
    } else {
        HttpHeaders httpHeaders = new HttpHeaders();
        for (String name : getHttpHeaderNames()) {
            List<String> values = webSocketHttpHeaders.get(name);
            if (values != null) {
                httpHeaders.put(name, values);
            }
        }
        return httpHeaders;
    }
}

17 View Source File : WebSessionIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

private String extractSessionId(HttpHeaders headers) {
    List<String> headerValues = headers.get("Set-Cookie");
    replacedertNotNull(headerValues);
    replacedertEquals(1, headerValues.size());
    for (String s : headerValues.get(0).split(";")) {
        if (s.startsWith("SESSION=")) {
            return s.substring("SESSION=".length());
        }
    }
    return null;
}

17 View Source File : RestTemplateTests.java
License : MIT License
Project Creator : Vip-Augus

// SPR-15066
@Test
public void requestInterceptorCanAddExistingHeaderValueWithoutBody() throws Exception {
    ClientHttpRequestInterceptor interceptor = (request, body, execution) -> {
        request.getHeaders().add("MyHeader", "MyInterceptorValue");
        return execution.execute(request, body);
    };
    template.setInterceptors(Collections.singletonList(interceptor));
    HttpHeaders requestHeaders = new HttpHeaders();
    mockSentRequest(POST, "https://example.com", requestHeaders);
    mockResponseStatus(HttpStatus.OK);
    HttpHeaders enreplacedyHeaders = new HttpHeaders();
    enreplacedyHeaders.add("MyHeader", "MyEnreplacedyValue");
    HttpEnreplacedy<Void> enreplacedy = new HttpEnreplacedy<>(null, enreplacedyHeaders);
    template.exchange("https://example.com", POST, enreplacedy, Void.clreplaced);
    replacedertThat(requestHeaders.get("MyHeader"), contains("MyEnreplacedyValue", "MyInterceptorValue"));
    verify(response).close();
}

private void logBody(String body, HttpHeaders headers) {
    MediaType contentType = headers.getContentType();
    List<String> contentEncoding = headers.get(CONTENT_ENCODING_HEADER);
    if (contentEncoding != null && !contentEncoding.contains("idenreplacedy")) {
        log.trace("  Body: encoded, not shown");
    } else {
        if (contentType != null && contentType.toString().startsWith(APPLICATION_JSON_HEADER)) {
            log.trace("  Body: {}", writeJSON(body));
        } else {
            log.trace("  Body: {}", body);
        }
    }
}

17 View Source File : CompositeHttpHeadersProviderTest.java
License : Apache License 2.0
Project Creator : SpringCloud

@Test
public void should_return_all_headers() {
    HttpHeadersProvider provider = new CompositeHttpHeadersProvider(asList(i -> {
        HttpHeaders headers = new HttpHeaders();
        headers.set("a", "1");
        headers.set("b", "2-a");
        return headers;
    }, i -> {
        HttpHeaders headers = new HttpHeaders();
        headers.set("b", "2-b");
        headers.set("c", "3");
        return headers;
    }));
    HttpHeaders headers = provider.getHeaders(null);
    replacedertThat(headers.get("a")).isEqualTo(singletonList("1"));
    replacedertThat(headers.get("b")).isEqualTo(asList("2-a", "2-b"));
    replacedertThat(headers.get("c")).isEqualTo(singletonList("3"));
}

17 View Source File : StaticHttpHeadersWriterTests.java
License : Apache License 2.0
Project Creator : spring-projects

@Test
public void writeHeadersWhenMultiHeaderAndSingleWrittenThenNoHeadersOverridden() {
    String headerValue = "other";
    headers.set(HttpHeaders.CACHE_CONTROL, headerValue);
    writer = StaticHttpHeadersWriter.builder().header(HttpHeaders.CACHE_CONTROL, CacheControlHttpHeadersWriter.CACHE_CONTRTOL_VALUE).header(HttpHeaders.PRAGMA, CacheControlHttpHeadersWriter.PRAGMA_VALUE).header(HttpHeaders.EXPIRES, CacheControlHttpHeadersWriter.EXPIRES_VALUE).build();
    writer.writeHttpHeaders(exchange);
    replacedertThat(headers).hreplacedize(1);
    replacedertThat(headers.get(HttpHeaders.CACHE_CONTROL)).containsOnly(headerValue);
}

17 View Source File : CacheControlHttpHeadersWriterTests.java
License : Apache License 2.0
Project Creator : spring-projects

@Test
public void writeHeadersWhenCacheControlThenNoCacheControlHeaders() {
    String cacheControl = "max-age=1234";
    headers.set(HttpHeaders.CACHE_CONTROL, cacheControl);
    writer.writeHttpHeaders(exchange);
    replacedertThat(headers.get(HttpHeaders.CACHE_CONTROL)).containsOnly(cacheControl);
}

17 View Source File : GatewayIntegrationTests.java
License : Apache License 2.0
Project Creator : spring-cloud

@Test
public void defaultFiltersWorks() {
    replacedertThat(this.properties.getDefaultFilters()).isNotEmpty();
    testClient.get().uri("/headers").header("Host", "www.addresponseheader.org").exchange().expectStatus().isOk().expectHeader().valueEquals("X-Response-Default-Foo", "Default-Bar").returnResult(Object.clreplaced).consumeWith(result -> {
        HttpHeaders httpHeaders = result.getResponseHeaders();
        replacedertThat(httpHeaders.get("X-Response-Default-Foo")).hreplacedize(1);
    });
}

@Test
public void dedupSingleValue() {
    config.setName(NAME_1);
    Mockito.when(headers.get(NAME_1)).thenReturn(Arrays.asList("1"));
    filter.dedupe(headers, config);
    Mockito.verify(headers).get(NAME_1);
    Mockito.verify(headers, Mockito.never()).set(Mockito.anyString(), Mockito.anyString());
}

@Test
public void dedupEmptyValues() {
    config.setName(NAME_1);
    Mockito.when(headers.get(NAME_1)).thenReturn(new ArrayList<>());
    filter.dedupe(headers, config);
    Mockito.verify(headers).get(NAME_1);
    Mockito.verify(headers, Mockito.never()).set(Mockito.anyString(), Mockito.anyString());
}

@Test
public void dedupMultipleValuesRetainFirst() {
    config.setName(NAME_1 + " " + NAME_2);
    Mockito.when(headers.get(NAME_1)).thenReturn(Arrays.asList("2", "3", "3", "4"));
    Mockito.when(headers.get(NAME_2)).thenReturn(Arrays.asList("true", "false"));
    filter.dedupe(headers, config);
    Mockito.verify(headers).get(NAME_1);
    Mockito.verify(headers).set(NAME_1, "2");
    Mockito.verify(headers).get(NAME_2);
    Mockito.verify(headers).set(NAME_2, "true");
    Mockito.verify(headers, Mockito.times(2)).set(Mockito.anyString(), Mockito.anyString());
}

@Test
public void dedupNullValues() {
    config.setName(NAME_1);
    Mockito.when(headers.get(NAME_1)).thenReturn(null);
    filter.dedupe(headers, config);
    Mockito.verify(headers).get(NAME_1);
    Mockito.verify(headers, Mockito.never()).set(Mockito.anyString(), Mockito.anyString());
}

17 View Source File : WebsocketRoutingFilter.java
License : Apache License 2.0
Project Creator : spring-cloud

@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
    changeSchemeIfIsWebSocketUpgrade(exchange);
    URI requestUrl = exchange.getRequiredAttribute(GATEWAY_REQUEST_URL_ATTR);
    String scheme = requestUrl.getScheme();
    if (isAlreadyRouted(exchange) || (!"ws".equals(scheme) && !"wss".equals(scheme))) {
        return chain.filter(exchange);
    }
    setAlreadyRouted(exchange);
    HttpHeaders headers = exchange.getRequest().getHeaders();
    HttpHeaders filtered = filterRequest(getHeadersFilters(), exchange);
    List<String> protocols = headers.get(SEC_WEBSOCKET_PROTOCOL);
    if (protocols != null) {
        protocols = headers.get(SEC_WEBSOCKET_PROTOCOL).stream().flatMap(header -> Arrays.stream(commaDelimitedListToStringArray(header))).map(String::trim).collect(Collectors.toList());
    }
    return this.webSocketService.handleRequest(exchange, new ProxyWebSocketHandler(requestUrl, this.webSocketClient, filtered, protocols));
}

17 View Source File : XForwardedHeadersFilter.java
License : Apache License 2.0
Project Creator : spring-cloud

private void write(HttpHeaders headers, String name, String value, boolean append) {
    if (append) {
        headers.add(name, value);
        // these headers should be treated as a single comma separated header
        List<String> values = headers.get(name);
        String delimitedValue = StringUtils.collectionToCommaDelimitedString(values);
        headers.set(name, delimitedValue);
    } else {
        headers.set(name, value);
    }
}

17 View Source File : ProxyExchange.java
License : Apache License 2.0
Project Creator : spring-cloud

private BodyBuilder headers(BodyBuilder builder) {
    Set<String> sensitive = this.sensitive;
    if (sensitive == null) {
        sensitive = DEFAULT_SENSITIVE;
    }
    proxy();
    for (String name : headers.keySet()) {
        if (sensitive.contains(name.toLowerCase())) {
            continue;
        }
        builder.header(name, headers.get(name).toArray(new String[0]));
    }
    return builder;
}

17 View Source File : WebSessionIntegrationTests.java
License : Apache License 2.0
Project Creator : SourceHot

private String extractSessionId(HttpHeaders headers) {
    List<String> headerValues = headers.get("Set-Cookie");
    replacedertThat(headerValues).isNotNull();
    replacedertThat(headerValues.size()).isEqualTo(1);
    for (String s : headerValues.get(0).split(";")) {
        if (s.startsWith("SESSION=")) {
            return s.substring("SESSION=".length());
        }
    }
    return null;
}

17 View Source File : RestTemplateTests.java
License : Apache License 2.0
Project Creator : SourceHot

// SPR-15066
@Test
public void requestInterceptorCanAddExistingHeaderValueWithoutBody() throws Exception {
    ClientHttpRequestInterceptor interceptor = (request, body, execution) -> {
        request.getHeaders().add("MyHeader", "MyInterceptorValue");
        return execution.execute(request, body);
    };
    template.setInterceptors(Collections.singletonList(interceptor));
    HttpHeaders requestHeaders = new HttpHeaders();
    mockSentRequest(POST, "https://example.com", requestHeaders);
    mockResponseStatus(HttpStatus.OK);
    HttpHeaders enreplacedyHeaders = new HttpHeaders();
    enreplacedyHeaders.add("MyHeader", "MyEnreplacedyValue");
    HttpEnreplacedy<Void> enreplacedy = new HttpEnreplacedy<>(null, enreplacedyHeaders);
    template.exchange("https://example.com", POST, enreplacedy, Void.clreplaced);
    replacedertThat(requestHeaders.get("MyHeader")).contains("MyEnreplacedyValue", "MyInterceptorValue");
    verify(response).close();
}

17 View Source File : ProductCompositeServiceImpl.java
License : MIT License
Project Creator : PacktPublishing

private HttpHeaders getHeaders(HttpHeaders requesthHeaders, String... headers) {
    LOG.trace("Will look for {} headers: {}", headers.length, headers);
    HttpHeaders h = new HttpHeaders();
    for (String header : headers) {
        List<String> value = requesthHeaders.get(header);
        if (value != null) {
            h.addAll(header, value);
        }
    }
    LOG.trace("Will transfer {}, headers: {}", h.size(), h);
    return h;
}

17 View Source File : ServerRequestUtils.java
License : Apache License 2.0
Project Creator : open-hand

public static String resolveHeader(ServerHttpRequest request, String key) {
    HttpHeaders headers = request.getHeaders();
    List<String> values = headers.get(key);
    if (values == null) {
        return null;
    }
    return values.stream().filter(value -> value != null && !value.isEmpty()).findFirst().orElseGet(() -> null);
}

17 View Source File : BasicHttpHeadersProviderTest.java
License : Apache License 2.0
Project Creator : onap

@Test
public void test_getHttpHeaders_ContainAuthorizationHeader() {
    final HttpHeadersProvider objUnderTest = new BasicHttpHeadersProvider(BASIC_AUTH_VALUE);
    final HttpHeaders actualHttpHeaders = objUnderTest.getHttpHeaders();
    replacedertEquals(Arrays.asList(BASIC_AUTH_VALUE), actualHttpHeaders.get(AUTHORIZATION_HEADER));
    replacedertEquals(MediaType.APPLICATION_JSON, actualHttpHeaders.getContentType());
}

17 View Source File : BasicHttpHeadersProviderTest.java
License : Apache License 2.0
Project Creator : onap

@Test
public void test_getHttpHeaders_ContentTypeIsJson() {
    final HttpHeadersProvider objUnderTest = new BasicHttpHeadersProvider();
    final HttpHeaders actualHttpHeaders = objUnderTest.getHttpHeaders();
    replacedertNull(actualHttpHeaders.get(AUTHORIZATION_HEADER));
    replacedertEquals(MediaType.APPLICATION_JSON, actualHttpHeaders.getContentType());
}

17 View Source File : RestTemplateTests.java
License : MIT License
Project Creator : mindcarver

// SPR-15066
@Test
public void requestInterceptorCanAddExistingHeaderValueWithoutBody() throws Exception {
    ClientHttpRequestInterceptor interceptor = (request, body, execution) -> {
        request.getHeaders().add("MyHeader", "MyInterceptorValue");
        return execution.execute(request, body);
    };
    template.setInterceptors(Collections.singletonList(interceptor));
    HttpHeaders requestHeaders = new HttpHeaders();
    mockSentRequest(POST, "http://example.com", requestHeaders);
    mockResponseStatus(HttpStatus.OK);
    HttpHeaders enreplacedyHeaders = new HttpHeaders();
    enreplacedyHeaders.add("MyHeader", "MyEnreplacedyValue");
    HttpEnreplacedy<Void> enreplacedy = new HttpEnreplacedy<>(null, enreplacedyHeaders);
    template.exchange("http://example.com", POST, enreplacedy, Void.clreplaced);
    replacedertThat(requestHeaders.get("MyHeader"), contains("MyEnreplacedyValue", "MyInterceptorValue"));
    verify(response).close();
}

17 View Source File : DefaultResponseCreator.java
License : Apache License 2.0
Project Creator : langtianya

/**
 * Copy all given headers.
 */
public DefaultResponseCreator headers(HttpHeaders headers) {
    for (String headerName : headers.keySet()) {
        for (String headerValue : headers.get(headerName)) {
            this.headers.add(headerName, headerValue);
        }
    }
    return this;
}

17 View Source File : FilterUtils.java
License : MIT License
Project Creator : ihuaylupo

public String getAuthToken(HttpHeaders requestHeaders) {
    if (requestHeaders.get(AUTH_TOKEN) != null) {
        List<String> header = requestHeaders.get(AUTH_TOKEN);
        return header.stream().findFirst().get();
    } else {
        return null;
    }
}

17 View Source File : FilterUtils.java
License : MIT License
Project Creator : ihuaylupo

public String getCorrelationId(HttpHeaders requestHeaders) {
    if (requestHeaders.get(CORRELATION_ID) != null) {
        List<String> header = requestHeaders.get(CORRELATION_ID);
        return header.stream().findFirst().get();
    } else {
        return null;
    }
}

17 View Source File : JwtTokenAuthenticationServiceTest.java
License : Apache License 2.0
Project Creator : Decathlon

@Test
void deleteAuthenticationCookie_returnHeaderContainingEmptyCookie_whenIsNotUsingHttps() {
    // Given
    // When
    when(tokenConfiguration.isUsingHttps()).thenReturn(false);
    // Then
    HttpHeaders header = tokenAuthenticationService.deleteAuthenticationCookie();
    replacedertThat(header).isNotNull().isNotEmpty();
    replacedertThat(header.get(HttpHeaders.SET_COOKIE).get(0)).contains("ara-access-token=;", "Path=/;", "Max-Age=0;", "HttpOnly;", "SameSite=Strict").doesNotContain("Secure");
}

17 View Source File : JwtTokenAuthenticationServiceTest.java
License : Apache License 2.0
Project Creator : Decathlon

@Test
void createAuthenticationResponseCookieHeader_returnHeaderContainingCookie_whenNoError() throws AuthenticationException {
    // Given
    Long tokenExpirationInSeconds = 3600L;
    String secret = "well_hidden_jwt_secret!";
    // When
    when(authenticationConfiguration.isEnabled()).thenReturn(true);
    when(tokenConfiguration.getAccessTokenExpirationInSecond()).thenReturn(tokenExpirationInSeconds);
    when(tokenConfiguration.getTokenSecret()).thenReturn(secret);
    when(tokenConfiguration.isUsingHttps()).thenReturn(true);
    // Then
    HttpHeaders header = tokenAuthenticationService.createAuthenticationResponseCookieHeader(Optional.empty());
    replacedertThat(header).isNotNull().isNotEmpty();
    replacedertThat(header.get(HttpHeaders.SET_COOKIE).get(0)).contains("Path=/;", "Max-Age=3600;", "Secure;", "HttpOnly;", "SameSite=Strict");
}

17 View Source File : JwtTokenAuthenticationServiceTest.java
License : Apache License 2.0
Project Creator : Decathlon

@Test
void deleteAuthenticationCookie_returnHeaderContainingEmptyCookie_whenIsUsingHttps() {
    // Given
    // When
    when(tokenConfiguration.isUsingHttps()).thenReturn(true);
    // Then
    HttpHeaders header = tokenAuthenticationService.deleteAuthenticationCookie();
    replacedertThat(header).isNotNull().isNotEmpty();
    replacedertThat(header.get(HttpHeaders.SET_COOKIE).get(0)).contains("ara-access-token=;", "Path=/;", "Max-Age=0;", "Secure;", "HttpOnly;", "SameSite=Strict");
}

17 View Source File : TestSecHubRestAPIClientHttpRequestInterceptor.java
License : MIT License
Project Creator : Daimler

@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
    /* we always create a new base64 token, because api token in test user data does change at runtime */
    HttpHeaders headers = request.getHeaders();
    List<String> x = headers.get("Content-Type");
    if (x == null || x.isEmpty()) {
        // headers.remove("Content-Type"); // strange, but sometimes there was a content-type (plain-text already added)
        headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
    }
    headers.remove("Authorization");
    if (!user.isAnonymous()) {
        String text = user.getUserId() + ":" + user.getApiToken();
        String base64Token = Base64.getEncoder().encodeToString(text.getBytes());
        headers.add("Authorization", "Basic " + base64Token);
    }
    LOG.info("...............REST call for user:" + user.getUserId() + "............................");
    return execution.execute(request, body);
}

17 View Source File : RestTemplateResponse.java
License : Apache License 2.0
Project Creator : crnk-project

@Override
public String getResponseHeader(String name) {
    List<String> values = headers.get(name);
    return values != null ? StringUtils.join(",", values) : null;
}

17 View Source File : RestExceptionHandlerTest.java
License : Apache License 2.0
Project Creator : adorsys

@Test
void preAuthorisationException() {
    PreAuthorisationException preAuthorisationException = new PreAuthorisationException(getErrorResponse(), "test error");
    ResponseEnreplacedy<?> actualResponse = exceptionHandler.handle(preAuthorisationException);
    replacedertThat(actualResponse).isNotNull().matches(res -> res.getStatusCodeValue() == 401).matches(res -> {
        HttpHeaders headers = res.getHeaders();
        List<String> originator = headers.get(X_GTW_ERROR_ORIGINATION);
        if (originator != null) {
            return originator.contains(ADAPTER);
        }
        return false;
    }).extracting(ResponseEnreplacedy::getBody).isInstanceOf(ErrorResponse.clreplaced).matches(body -> ((ErrorResponse) body).getLinks().get(EMBEDDED_PRE_AUTH).getHref().equals(PRE_AUTH_TOKEN_URI));
}

16 View Source File : XmHttpEntityUtils.java
License : Apache License 2.0
Project Creator : xm-online

public static String getFileName(HttpHeaders xmImageHeaders) {
    MediaType contentType;
    String fileName = null;
    List<String> fileNames = xmImageHeaders.get(XM_HEADER_CONTENT_NAME);
    if (!CollectionUtils.isEmpty(fileNames)) {
        String value = fileNames.iterator().next();
        if (StringUtils.isNoneBlank(value)) {
            fileName = value;
        }
    }
    // generate file name
    if (fileName == null) {
        fileName = "file";
        // try to get file extension
        contentType = xmImageHeaders.getContentType();
        if (contentType != null && !contentType.isWildcardSubtype()) {
            fileName += "." + contentType.getSubtype().toLowerCase();
        }
    }
    return fileName;
}

16 View Source File : ResourceWebHandlerTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void getResource() throws Exception {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
    setPathWithinHandlerMapping(exchange, "foo.css");
    this.handler.handle(exchange).block(TIMEOUT);
    HttpHeaders headers = exchange.getResponse().getHeaders();
    replacedertEquals(MediaType.parseMediaType("text/css"), headers.getContentType());
    replacedertEquals(17, headers.getContentLength());
    replacedertEquals("max-age=3600", headers.getCacheControl());
    replacedertTrue(headers.containsKey("Last-Modified"));
    replacedertEquals(headers.getLastModified() / 1000, resourceLastModifiedDate("test/foo.css") / 1000);
    replacedertEquals("bytes", headers.getFirst("Accept-Ranges"));
    replacedertEquals(1, headers.get("Accept-Ranges").size());
    replacedertResponseBody(exchange, "h1 { color:red; }");
}

16 View Source File : ResourceWebHandlerTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void getResourceFromAlternatePath() throws Exception {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
    setPathWithinHandlerMapping(exchange, "baz.css");
    this.handler.handle(exchange).block(TIMEOUT);
    HttpHeaders headers = exchange.getResponse().getHeaders();
    replacedertEquals(MediaType.parseMediaType("text/css"), headers.getContentType());
    replacedertEquals(17, headers.getContentLength());
    replacedertEquals("max-age=3600", headers.getCacheControl());
    replacedertTrue(headers.containsKey("Last-Modified"));
    replacedertEquals(headers.getLastModified() / 1000, resourceLastModifiedDate("testalternatepath/baz.css") / 1000);
    replacedertEquals("bytes", headers.getFirst("Accept-Ranges"));
    replacedertEquals(1, headers.get("Accept-Ranges").size());
    replacedertResponseBody(exchange, "h1 { color:red; }");
}

See More Examples