com.github.tomakehurst.wiremock.http.HttpHeader Java Examples
The following examples show how to use
com.github.tomakehurst.wiremock.http.HttpHeader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedirectTest.java From gradle-download-task with Apache License 2.0 | 6 votes |
@Override public Response transform(Request request, Response response, FileSource files, Parameters parameters) { if (redirects == null) { redirects = parameters.getInt("redirects"); } String nl; if (redirects > 1) { redirects--; nl = "/" + REDIRECT + "?r=" + redirects; } else { nl = "/" + TEST_FILE_NAME; } return Response.Builder.like(response) .but().headers(response.getHeaders() .plus(new HttpHeader("Location", nl))) .build(); }
Example #2
Source File: WireMockTestUtils.java From junit-servers with MIT License | 6 votes |
private static void stubRequest(String method, String endpoint, int status, Collection<Pair> headers, String body) { UrlPattern urlPattern = urlEqualTo(endpoint); MappingBuilder request = request(method, urlPattern); ResponseDefinitionBuilder response = aResponse().withStatus(status); HttpHeaders httpHeaders = new HttpHeaders(); for (Pair header : headers) { String name = header.getO1(); List<String> values = header.getO2(); HttpHeader h = new HttpHeader(name, values); httpHeaders = httpHeaders.plus(h); } response.withHeaders(httpHeaders); if (body != null) { response.withBody(body); } stubFor(request.willReturn(response)); }
Example #3
Source File: WireMockBase.java From blueocean-plugin with MIT License | 6 votes |
@Override public Response transform(Request request, Response response, FileSource files, Parameters parameters) { // if gzipped, ungzip they body and discard the Content-Encoding header if (response.getHeaders().getHeader("Content-Encoding").containsValue("gzip")) { Iterable<HttpHeader> headers = Iterables.filter( response.getHeaders().all(), (HttpHeader header) -> header != null && !header.keyEquals("Content-Encoding") && !header.containsValue("gzip") ); return Response.Builder.like(response) .but() .body(Gzip.unGzip(response.getBody())) .headers(new HttpHeaders(headers)) .build(); } return response; }
Example #4
Source File: Webhooks.java From wiremock-webhooks-extension with Apache License 2.0 | 6 votes |
private static HttpUriRequest buildRequest(WebhookDefinition definition) { HttpUriRequest request = getHttpRequestFor( definition.getMethod(), definition.getUrl().toString() ); for (HttpHeader header: definition.getHeaders().all()) { request.addHeader(header.key(), header.firstValue()); } if (definition.getMethod().hasEntity()) { HttpEntityEnclosingRequestBase entityRequest = (HttpEntityEnclosingRequestBase) request; entityRequest.setEntity(new ByteArrayEntity(definition.getBinaryBody())); } return request; }
Example #5
Source File: ContractExchangeHandler.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
@Override public com.github.tomakehurst.wiremock.http.HttpHeaders getHeaders() { com.github.tomakehurst.wiremock.http.HttpHeaders target = new com.github.tomakehurst.wiremock.http.HttpHeaders(); HttpHeaders headers = this.result.getRequestHeaders(); for (String key : headers.keySet()) { target = target.plus(new HttpHeader(key, headers.getValuesAsList(key))); } return target; }
Example #6
Source File: RequestVerifierFilter.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Override public HttpHeaders getHeaders() { List<HttpHeader> headers = new ArrayList<>(); for (Header header : request.getHeaders()) { String value = header.getValue(); if ("accept".equals(header.getName().toLowerCase()) && "*/*".equals(value)) { continue; } headers.add(new HttpHeader(header.getName(), header.getValue())); } return new HttpHeaders(headers); }
Example #7
Source File: RequestVerifierFilter.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Override public HttpHeader header(String key) { String value = request.getHeaders().getValue(key); if ("accept".equals(key.toLowerCase()) && "*/*".equals(value)) { return null; } return new HttpHeader(key, value); }
Example #8
Source File: WebhookDefinition.java From wiremock-webhooks-extension with Apache License 2.0 | 5 votes |
public WebhookDefinition withHeader(String key, String... values) { if (headers == null) { headers = newArrayList(); } headers.add(new HttpHeader(key, values)); return this; }
Example #9
Source File: WireMockSnippet.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
private HttpHeaders responseHeaders(Operation operation) { org.springframework.http.HttpHeaders headers = operation.getResponse() .getHeaders(); HttpHeaders result = new HttpHeaders(); for (String name : headers.keySet()) { if (!this.headerBlackList.contains(name.toLowerCase())) { result = result.plus(new HttpHeader(name, headers.get(name))); } } return result; }
Example #10
Source File: ContractExchangeHandler.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
private Part partFromServletPart(javax.servlet.http.Part part) { return new Part() { @Override public String getName() { return part.getName(); } @Override public HttpHeader getHeader(String name) { return new HttpHeader(name, part.getHeader(name)); } @Override public com.github.tomakehurst.wiremock.http.HttpHeaders getHeaders() { com.github.tomakehurst.wiremock.http.HttpHeaders headers = new com.github.tomakehurst.wiremock.http.HttpHeaders(); for (String s : part.getHeaderNames()) { headers.plus(new HttpHeader(s, part.getHeader(s))); } return headers; } @Override public Body getBody() { try { byte[] targetArray = new byte[part.getInputStream().available()]; return new Body(targetArray); } catch (IOException e) { throw new IllegalStateException(e); } } }; }
Example #11
Source File: AbstractInstancesProxyControllerIntegrationTest.java From Moss with Apache License 2.0 | 5 votes |
@Override public Response transform(Request request, Response response, FileSource files, Parameters parameters) { return Response.Builder.like(response) .headers(HttpHeaders.copyOf(response.getHeaders()) .plus(new HttpHeader("Connection", "Close"))) .build(); }
Example #12
Source File: WireMockRestServiceServer.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
private MediaType contentType(ResponseDefinition response) { String value = null; if (response.getHeaders() != null) { HttpHeader header = response.getHeaders().getHeader("Content-Type"); if (header != null && header.isPresent()) { value = header.firstValue(); } } return value == null ? MediaType.TEXT_PLAIN : MediaType.valueOf(value); }
Example #13
Source File: WireMockRestServiceServer.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
private HttpHeaders responseHeaders(ResponseDefinition response) { HttpHeaders headers = new HttpHeaders(); if (response.getHeaders() != null) { for (HttpHeader header : response.getHeaders().all()) { if (!header.keyEquals("Content-Type")) { for (String value : header.values()) { headers.add(header.key(), value); } } } } return headers; }
Example #14
Source File: SdkHttpResponseTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private void stubWithHeaders(Map<String, List<String>> headers) { HttpHeaders httpHeaders = new HttpHeaders(headers.entrySet().stream().map(entry -> new HttpHeader(entry.getKey(), entry.getValue())) .collect(Collectors.toList())); stubFor(post(anyUrl()).willReturn(aResponse() .withStatus(200) .withStatusMessage(STATUS_TEXT) .withHeaders(httpHeaders) .withBody(JSON_BODY))); }
Example #15
Source File: WiremockStyxRequestAdapter.java From styx with Apache License 2.0 | 5 votes |
@Override public HttpHeaders getHeaders() { List<HttpHeader> list = stream(styxRequest.headers().spliterator(), false) .map(styxHeader -> httpHeader(styxHeader.name(), styxHeader.value())) .collect(toList()); return new HttpHeaders(list); }
Example #16
Source File: AbstractHttpClientInstrumentationTest.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Override public <S> void forEach(String headerName, LoggedRequest loggedRequest, S state, HeaderConsumer<String, S> consumer) { HttpHeaders headers = loggedRequest.getHeaders(); if (headers != null) { HttpHeader header = headers.getHeader(headerName); if (header != null) { List<String> values = header.values(); for (int i = 0, size = values.size(); i < size; i++) { consumer.accept(values.get(i), state); } } } }
Example #17
Source File: ContractExchangeHandler.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
@Override public HttpHeader header(String key) { HttpHeaders headers = this.result.getRequestHeaders(); return headers.containsKey(key) ? new HttpHeader(key, headers.getValuesAsList(key)) : null; }
Example #18
Source File: WebhookDefinition.java From wiremock-webhooks-extension with Apache License 2.0 | 4 votes |
public WebhookDefinition withHeaders(List<HttpHeader> headers) { this.headers = headers; return this; }
Example #19
Source File: WiremockStyxRequestAdapter.java From styx with Apache License 2.0 | 4 votes |
@Override public HttpHeader header(String key) { List<String> values = styxRequest.headers(key); return httpHeader(key, values.toArray(new String[values.size()])); }
Example #20
Source File: ConnectionCloseExtension.java From spring-boot-admin with Apache License 2.0 | 4 votes |
@Override public Response transform(Request request, Response response, FileSource files, Parameters parameters) { return Response.Builder.like(response) .headers(HttpHeaders.copyOf(response.getHeaders()).plus(new HttpHeader("Connection", "Close"))).build(); }
Example #21
Source File: CustomVelocityResponseTransformer.java From AuTe-Framework with Apache License 2.0 | 4 votes |
private boolean isPresentConvertCommand(HttpHeader header) { return header != null && header.isPresent() && "true".equals(header.firstValue()) ; }