@Override public PartBuilder header(String headerName, String... headerValues) { this.headers.addAll(headerName, Arrays.asList(headerValues)); return this; }
@Override public PartBuilder header(String headerName, String... headerValues) { this.headers.addAll(headerName, Arrays.asList(headerValues)); return this; }
public DefaultServerResponseBuilder(ServerResponse other) { Assert.notNull(other, "ServerResponse must not be null"); this.statusCode = (other instanceof AbstractServerResponse ? ((AbstractServerResponse) other).statusCode : other.statusCode().value()); this.headers.addAll(other.headers()); }
@Override public HttpHeaders getHeaders(Instance instance) { HttpHeaders headers = new HttpHeaders(); delegates.forEach(delegate -> headers.addAll(delegate.getHeaders(instance))); return headers; } }
@Override public WebClientProvider withDefaultHeaders(HttpHeaders headers) { Assert.notNull(headers, "HttpHeaders must not be null."); HttpHeaders merged = new HttpHeaders(); merged.addAll(this.headers); merged.addAll(headers); return new DefaultWebClientProvider(this.scheme, this.connector, errorListener, merged); }
@Override public HttpHeaders filter(HttpHeaders input, ServerWebExchange exchange) { HttpHeaders filtered = new HttpHeaders(); input.entrySet().stream() .filter(entry -> !this.headers.contains(entry.getKey().toLowerCase())) .forEach(entry -> filtered.addAll(entry.getKey(), entry.getValue())); return filtered; }
private HandshakeInfo createHandshakeInfo(ServerWebExchange exchange, ServerHttpRequest request, @Nullable String protocol, Map<String, Object> attributes) { URI uri = request.getURI(); // Copy request headers, as they might be pooled and recycled by // the server implementation once the handshake HTTP exchange is done. HttpHeaders headers = new HttpHeaders(); headers.addAll(request.getHeaders()); Mono<Principal> principal = exchange.getPrincipal(); String logPrefix = exchange.getLogPrefix(); InetSocketAddress remoteAddress = request.getRemoteAddress(); return new HandshakeInfo(uri, headers, principal, protocol, remoteAddress, attributes, logPrefix); }
HttpEntity<?> httpEntity = (HttpEntity<?>) part; partBody = httpEntity.getBody(); partHeaders.addAll(httpEntity.getHeaders());
private ClientRequest.Builder initRequestBuilder() { if (defaultRequest != null) { defaultRequest.accept(this); } return ClientRequest.create(this.httpMethod, initUri()) .headers(headers -> headers.addAll(initHeaders())) .cookies(cookies -> cookies.addAll(initCookies())) .attributes(attributes -> attributes.putAll(this.attributes)); }
public DefaultClientRequestBuilder(ClientRequest other) { Assert.notNull(other, "ClientRequest must not be null"); this.method = other.method(); this.url = other.url(); headers(headers -> headers.addAll(other.headers())); cookies(cookies -> cookies.addAll(other.cookies())); attributes(attributes -> attributes.putAll(other.attributes())); body(other.body()); }
static HttpHeaders getTokenRequestHeaders(ClientRegistration clientRegistration) { HttpHeaders headers = new HttpHeaders(); headers.addAll(DEFAULT_TOKEN_REQUEST_HEADERS); if (ClientAuthenticationMethod.BASIC.equals(clientRegistration.getClientAuthenticationMethod())) { headers.setBasicAuth(clientRegistration.getClientId(), clientRegistration.getClientSecret()); } return headers; }
public DefaultClientResponseBuilder(ClientResponse other) { Assert.notNull(other, "ClientResponse must not be null"); this.strategies = other.strategies(); statusCode(other.statusCode()); headers(headers -> headers.addAll(other.headers().asHttpHeaders())); cookies(cookies -> cookies.addAll(other.cookies())); }
public DefaultServerRequestBuilder(ServerRequest other) { Assert.notNull(other, "ServerRequest must not be null"); this.messageReaders = other.messageReaders(); this.exchange = other.exchange(); this.methodName = other.methodName(); this.uri = other.uri(); headers(headers -> headers.addAll(other.headers().asHttpHeaders())); cookies(cookies -> cookies.addAll(other.cookies())); attributes(attributes -> attributes.putAll(other.attributes())); }
@Override public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException { if (this.iterator.hasNext()) { ClientHttpRequestInterceptor nextInterceptor = this.iterator.next(); return nextInterceptor.intercept(request, body, this); } else { HttpMethod method = request.getMethod(); Assert.state(method != null, "No standard HTTP method"); ClientHttpRequest delegate = requestFactory.createRequest(request.getURI(), method); request.getHeaders().forEach((key, value) -> delegate.getHeaders().addAll(key, value)); if (body.length > 0) { if (delegate instanceof StreamingHttpOutputMessage) { StreamingHttpOutputMessage streamingOutputMessage = (StreamingHttpOutputMessage) delegate; streamingOutputMessage.setBody(outputStream -> StreamUtils.copy(body, outputStream)); } else { StreamUtils.copy(body, delegate.getBody()); } } return delegate.execute(); } } }
protected WebClient createWebClientForSocketAddress(InetSocketAddress socketAddress) { Builder builder = WebClient.builder().defaultHeaders(it -> it.addAll(getDefaultHeaders())); if (connector != null) { builder = builder.clientConnector(connector); } String baseUrl = String.format("%s://%s:%d", this.scheme, socketAddress.getHostString(), socketAddress.getPort()); return builder.baseUrl(baseUrl).filter((request, next) -> next.exchange(request).doOnError(errorListener)).build(); } }
public static ExchangeFilterFunction addHeaders(HttpHeadersProvider httpHeadersProvider) { return toExchangeFilterFunction((instance, request, next) -> { ClientRequest newRequest = ClientRequest.from(request) .headers(headers -> headers.addAll(httpHeadersProvider.getHeaders( instance))) .build(); return next.exchange(newRequest); }); }
@RequestMapping(path = REQUEST_MAPPING_PATH, method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST, RequestMethod.PUT, RequestMethod.PATCH, RequestMethod.DELETE, RequestMethod.OPTIONS}) public Mono<Void> endpointProxy(@PathVariable("instanceId") String instanceId, ServerHttpRequest request, ServerHttpResponse response) { String endpointLocalPath = getEndpointLocalPath(request.getPath().pathWithinApplication().value()); URI uri = UriComponentsBuilder.fromPath(endpointLocalPath) .query(request.getURI().getRawQuery()) .build(true) .toUri(); return super.forward(instanceId, uri, request.getMethod(), request.getHeaders(), () -> BodyInserters.fromDataBuffers(request.getBody())).flatMap(clientResponse -> { response.setStatusCode(clientResponse.statusCode()); response.getHeaders().addAll(filterHeaders(clientResponse.headers().asHttpHeaders())); return response.writeAndFlushWith(clientResponse.body(BodyExtractors.toDataBuffers()).window(1)); }); } }
HttpHeaders responseHeaders = response.getHeaders(); responseHeaders.addAll(HttpHeaders.VARY, Arrays.asList(HttpHeaders.ORIGIN, HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS));
HttpHeaders responseHeaders = response.getHeaders(); response.getHeaders().addAll(HttpHeaders.VARY, Arrays.asList(HttpHeaders.ORIGIN, HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS));
@Test public void headers() { HttpHeaders newHeaders = new HttpHeaders(); newHeaders.set("foo", "bar"); Mono<ServerResponse> result = ServerResponse.ok().headers(headers -> headers.addAll(newHeaders)).build(); StepVerifier.create(result) .expectNextMatches(response -> newHeaders.equals(response.headers())) .expectComplete() .verify(); }