org.springframework.http.HttpHeaders#readOnlyHttpHeaders ( )源码实例Demo

下面列出了org.springframework.http.HttpHeaders#readOnlyHttpHeaders ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: haven-platform   文件: RegistryAuthInterceptor.java
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
                                    final ClientHttpRequestExecution execution) throws IOException {
    final HttpHeaders headers = request.getHeaders();
    ClientHttpResponse execute = execution.execute(request, body);

    if (execute.getStatusCode() == HttpStatus.UNAUTHORIZED) {
        List<String> list = execute.getHeaders().get("Www-Authenticate");
        if (!CollectionUtils.isEmpty(list)) {
            String tokenString = list.get(0);
            RegistryAuthAdapter.AuthContext ctx = new RegistryAuthAdapter.AuthContext(headers,
              HttpHeaders.readOnlyHttpHeaders(headers),
              tokenString);
            adapter.handle(ctx);
            return execution.execute(request, body);
        }
    }
    return execute;
}
 
/**
 * Class constructor that associates a user with the WebSocket session.
 *
 * @param headers the headers of the handshake request
 * @param attributes attributes from the HTTP handshake to associate with the WebSocket session
 * @param localAddress the address on which the request was received
 * @param remoteAddress the address of the remote client
 * @param user the user associated with the session; if {@code null} we'll
 * 	fallback on the user available in the underlying WebSocket session
 */
public StandardWebSocketSession(HttpHeaders headers, Map<String, Object> attributes,
		InetSocketAddress localAddress, InetSocketAddress remoteAddress, Principal user) {

	super(attributes);
	headers = (headers != null) ? headers : new HttpHeaders();
	this.handshakeHeaders = HttpHeaders.readOnlyHttpHeaders(headers);
	this.user = user;
	this.localAddress = localAddress;
	this.remoteAddress = remoteAddress;
}
 
protected AbstractServerResponse(
		int statusCode, HttpHeaders headers, MultiValueMap<String, ResponseCookie> cookies,
		Map<String, Object> hints) {

	this.statusCode = statusCode;
	this.headers = HttpHeaders.readOnlyHttpHeaders(headers);
	this.cookies = CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(cookies));
	this.hints = hints;
}
 
@Override
public void initializeNativeSession(Session session) {
	super.initializeNativeSession(session);

	this.uri = session.getUpgradeRequest().getRequestURI();

	HttpHeaders headers = new HttpHeaders();
	headers.putAll(session.getUpgradeRequest().getHeaders());
	this.headers = HttpHeaders.readOnlyHttpHeaders(headers);

	this.acceptedProtocol = session.getUpgradeResponse().getAcceptedSubProtocol();

	List<ExtensionConfig> jettyExtensions = session.getUpgradeResponse().getExtensions();
	if (!CollectionUtils.isEmpty(jettyExtensions)) {
		List<WebSocketExtension> extensions = new ArrayList<>(jettyExtensions.size());
		for (ExtensionConfig jettyExtension : jettyExtensions) {
			extensions.add(new WebSocketExtension(jettyExtension.getName(), jettyExtension.getParameters()));
		}
		this.extensions = Collections.unmodifiableList(extensions);
	}
	else {
		this.extensions = Collections.emptyList();
	}

	if (this.user == null) {
		this.user = session.getUpgradeRequest().getUserPrincipal();
	}
}
 
@Override
public void initializeNativeSession(Session session) {
	super.initializeNativeSession(session);

	this.uri = session.getUpgradeRequest().getRequestURI();

	HttpHeaders headers = new HttpHeaders();
	headers.putAll(session.getUpgradeRequest().getHeaders());
	this.headers = HttpHeaders.readOnlyHttpHeaders(headers);

	this.acceptedProtocol = session.getUpgradeResponse().getAcceptedSubProtocol();

	List<ExtensionConfig> jettyExtensions = session.getUpgradeResponse().getExtensions();
	if (!CollectionUtils.isEmpty(jettyExtensions)) {
		List<WebSocketExtension> extensions = new ArrayList<>(jettyExtensions.size());
		for (ExtensionConfig jettyExtension : jettyExtensions) {
			extensions.add(new WebSocketExtension(jettyExtension.getName(), jettyExtension.getParameters()));
		}
		this.extensions = Collections.unmodifiableList(extensions);
	}
	else {
		this.extensions = Collections.emptyList();
	}

	if (this.user == null) {
		this.user = session.getUpgradeRequest().getUserPrincipal();
	}
}
 
protected AbstractServerResponse(
		int statusCode, HttpHeaders headers, MultiValueMap<String, ResponseCookie> cookies) {

	this.statusCode = statusCode;
	this.headers = HttpHeaders.readOnlyHttpHeaders(headers);
	this.cookies = CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(cookies));
}
 
源代码7 项目: lams   文件: AbstractAsyncClientHttpRequest.java
@Override
public final HttpHeaders getHeaders() {
	return (this.executed ? HttpHeaders.readOnlyHttpHeaders(this.headers) : this.headers);
}
 
private static HttpHeaders unmodifiableCopy(HttpHeaders headers) {
	return HttpHeaders.readOnlyHttpHeaders(headers);
}
 
源代码9 项目: spring-batch-lightmin   文件: RequestUtil.java
public static <T> HttpEntity<T> createApplicationJsonEntity(final T body) {
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
    return new HttpEntity<>(body, HttpHeaders.readOnlyHttpHeaders(headers));
}
 
@Override
public HttpHeaders getHeaders() {
	return (this.headersWritten ? HttpHeaders.readOnlyHttpHeaders(this.headers) : this.headers);
}
 
@Override
public HttpHeaders getHeaders() {
	return (this.body != null ? HttpHeaders.readOnlyHttpHeaders(this.headers) : this.headers);
}
 
/**
 * Private constructor that can create read-only {@code WebSocketHttpHeader} instances.
 */
private WebSocketHttpHeaders(HttpHeaders headers, boolean readOnly) {
	this.headers = readOnly ? HttpHeaders.readOnlyHttpHeaders(headers) : headers;
}
 
源代码13 项目: spring-analysis-note   文件: MockServerRequest.java
@Override
public HttpHeaders asHttpHeaders() {
	return HttpHeaders.readOnlyHttpHeaders(delegate());
}
 
/**
 * Private constructor that can create read-only {@code WebSocketHttpHeader} instances.
 */
private WebSocketHttpHeaders(HttpHeaders headers, boolean readOnly) {
	this.headers = readOnly ? HttpHeaders.readOnlyHttpHeaders(headers) : headers;
}
 
源代码15 项目: java-technology-stack   文件: MockServerRequest.java
@Override
public HttpHeaders asHttpHeaders() {
	return HttpHeaders.readOnlyHttpHeaders(delegate());
}
 
@Override
public HttpHeaders asHttpHeaders() {
	return HttpHeaders.readOnlyHttpHeaders(delegate());
}
 
@Override
public final HttpHeaders getHeaders() {
	return (this.executed ? HttpHeaders.readOnlyHttpHeaders(this.headers) : this.headers);
}
 
@Override
public HttpHeaders getHeaders() {
	return (this.headersWritten ? HttpHeaders.readOnlyHttpHeaders(this.headers) : this.headers);
}
 
源代码19 项目: lams   文件: FormHttpMessageConverter.java
@Override
public HttpHeaders getHeaders() {
	return (this.headersWritten ? HttpHeaders.readOnlyHttpHeaders(this.headers) : this.headers);
}
 
@Override
public HttpHeaders getHeaders() {
	return (this.headersWritten ? HttpHeaders.readOnlyHttpHeaders(this.headers) : this.headers);
}