Java Code Examples for org.springframework.http.HttpHeaders#keySet()

The following examples show how to use org.springframework.http.HttpHeaders#keySet() . 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: JettyXhrTransport.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private static void addHttpHeaders(Request request, HttpHeaders headers) {
	for (String name : headers.keySet()) {
		for (String value : headers.get(name)) {
			request.header(name, value);
		}
	}
}
 
Example 2
Source File: WebClientTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/")
public Map<String, String> home(@RequestHeader HttpHeaders headers) {
	Map<String, String> map = new HashMap<>();
	for (String key : headers.keySet()) {
		map.put(key, headers.getFirst(key));
	}
	return map;
}
 
Example 3
Source File: GdaxExchangeImpl.java    From gdax-java with MIT License 5 votes vote down vote up
private void curlRequest(String method, String jsonBody, HttpHeaders headers, String resource) {
    String curlTest = "curl ";
    for (String key : headers.keySet()){
        curlTest +=  "-H '" + key + ":" + headers.get(key).get(0) + "' ";
    }
    if (!jsonBody.equals(""))
        curlTest += "-d '" + jsonBody + "' ";

    curlTest += "-X " + method + " " + getBaseUrl() + resource;
    log.debug(curlTest);
}
 
Example 4
Source File: HeaderUtils.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
public static MessageHeaders fromHttp(HttpHeaders headers) {
	Map<String, Object> map = new LinkedHashMap<>();
	for (String name : headers.keySet()) {
		Collection<?> values = multi(headers.get(name));
		name = name.toLowerCase();
		Object value = values == null ? null
				: (values.size() == 1 ? values.iterator().next() : values);
		if (name.toLowerCase().equals(HttpHeaders.CONTENT_TYPE.toLowerCase())) {
			name = MessageHeaders.CONTENT_TYPE;
		}
		map.put(name, value);
	}
	return new MessageHeaders(map);
}
 
Example 5
Source File: HeaderUtils.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
public static HttpHeaders sanitize(HttpHeaders request) {
	HttpHeaders result = new HttpHeaders();
	for (String name : request.keySet()) {
		List<String> value = request.get(name);
		name = name.toLowerCase();
		if (!IGNORED.containsKey(name) && !REQUEST_ONLY.containsKey(name)) {
			result.put(name, value);
		}
	}
	return result;
}
 
Example 6
Source File: ContractExchangeHandler.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: MockHttpServletRequestBuilder.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Add all headers to the request. Values are always added.
 * @param httpHeaders the headers and values to add
 */
public MockHttpServletRequestBuilder headers(HttpHeaders httpHeaders) {
	MediaType mediaType = httpHeaders.getContentType();
	if (mediaType != null) {
		this.contentType = mediaType.toString();
	}
	for (String name : httpHeaders.keySet()) {
		Object[] values = ObjectUtils.toObjectArray(httpHeaders.get(name).toArray());
		addToMultiValueMap(this.headers, name, values);
	}
	return this;
}
 
Example 8
Source File: UndertowXhrTransport.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private static void addHttpHeaders(ClientRequest request, HttpHeaders headers) {
	HeaderMap headerMap = request.getRequestHeaders();
	for (String name : headers.keySet()) {
		for (String value : headers.get(name)) {
			headerMap.add(HttpString.tryFromString(name), value);
		}
	}
}
 
Example 9
Source File: AbstractTyrusRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private RequestContext createRequestContext(HttpServletRequest request, String endpointPath, HttpHeaders headers) {
	RequestContext context =
			RequestContext.Builder.create()
					.requestURI(URI.create(endpointPath))
					.userPrincipal(request.getUserPrincipal())
					.secure(request.isSecure())
				//	.remoteAddr(request.getRemoteAddr())  # Not available in 1.3.5
					.build();
	for (String header : headers.keySet()) {
		context.getHeaders().put(header, headers.get(header));
	}
	return context;
}
 
Example 10
Source File: JettyWebSocketClient.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler,
		HttpHeaders headers, final URI uri, List<String> protocols,
		List<WebSocketExtension> extensions,  Map<String, Object> attributes) {

	final ClientUpgradeRequest request = new ClientUpgradeRequest();
	request.setSubProtocols(protocols);

	for (WebSocketExtension e : extensions) {
		request.addExtensions(new WebSocketToJettyExtensionConfigAdapter(e));
	}

	for (String header : headers.keySet()) {
		request.setHeader(header, headers.get(header));
	}

	Principal user = getUser();
	final JettyWebSocketSession wsSession = new JettyWebSocketSession(attributes, user);
	final JettyWebSocketHandlerAdapter listener = new JettyWebSocketHandlerAdapter(wsHandler, wsSession);

	Callable<WebSocketSession> connectTask = new Callable<WebSocketSession>() {
		@Override
		public WebSocketSession call() throws Exception {
			Future<Session> future = client.connect(listener, uri, request);
			future.get();
			return wsSession;
		}
	};

	if (this.taskExecutor != null) {
		return this.taskExecutor.submitListenable(connectTask);
	}
	else {
		ListenableFutureTask<WebSocketSession> task = new ListenableFutureTask<WebSocketSession>(connectTask);
		task.run();
		return task;
	}
}
 
Example 11
Source File: AbstractNcssController.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void setResponseHeaders(HttpServletResponse response, HttpHeaders httpHeaders) {
  Set<String> keySet = httpHeaders.keySet();
  for (String key : keySet) {
    if (httpHeaders.containsKey(key)) { // LOOK why test again?
      response.setHeader(key, httpHeaders.get(key).get(0)); // LOOK why only first one ?
    }
  }
}
 
Example 12
Source File: DefaultCorsProcessor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private List<String> getHeadersToUse(ServerHttpRequest request, boolean isPreFlight) {
	HttpHeaders headers = request.getHeaders();
	return (isPreFlight ? headers.getAccessControlRequestHeaders() : new ArrayList<>(headers.keySet()));
}
 
Example 13
Source File: DefaultCorsProcessor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private List<String> getHeadersToUse(ServerHttpRequest request, boolean isPreFlight) {
	HttpHeaders headers = request.getHeaders();
	return (isPreFlight ? headers.getAccessControlRequestHeaders() : new ArrayList<String>(headers.keySet()));
}
 
Example 14
Source File: ContractExchangeHandler.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
private void addResponseHeaders(ResponseDefinitionBuilder definition,
		HttpHeaders httpHeaders) {
	for (String name : httpHeaders.keySet()) {
		definition.withHeader(name, httpHeaders.get(name).toArray(new String[0]));
	}
}
 
Example 15
Source File: DefaultCorsProcessor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private List<String> getHeadersToUse(ServerHttpRequest request, boolean isPreFlight) {
	HttpHeaders headers = request.getHeaders();
	return (isPreFlight ? headers.getAccessControlRequestHeaders() : new ArrayList<String>(headers.keySet()));
}
 
Example 16
Source File: DefaultCorsProcessor.java    From java-technology-stack with MIT License 4 votes vote down vote up
private List<String> getHeadersToUse(ServerHttpRequest request, boolean isPreFlight) {
	HttpHeaders headers = request.getHeaders();
	return (isPreFlight ? headers.getAccessControlRequestHeaders() : new ArrayList<>(headers.keySet()));
}
 
Example 17
Source File: DefaultCorsProcessor.java    From java-technology-stack with MIT License 4 votes vote down vote up
private List<String> getHeadersToUse(ServerHttpRequest request, boolean isPreFlight) {
	HttpHeaders headers = request.getHeaders();
	return (isPreFlight ? headers.getAccessControlRequestHeaders() : new ArrayList<>(headers.keySet()));
}
 
Example 18
Source File: DefaultCorsProcessor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private List<String> getHeadersToUse(ServerHttpRequest request, boolean isPreFlight) {
	HttpHeaders headers = request.getHeaders();
	return (isPreFlight ? headers.getAccessControlRequestHeaders() : new ArrayList<>(headers.keySet()));
}