Handler StreamingHttpOutputMessage in XHR transport
Closes gh-23030
This commit is contained in:
parent
331463739d
commit
b296545af8
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -27,6 +27,7 @@ import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.http.StreamingHttpOutputMessage;
|
||||||
import org.springframework.http.client.ClientHttpRequest;
|
import org.springframework.http.client.ClientHttpRequest;
|
||||||
import org.springframework.http.client.ClientHttpResponse;
|
import org.springframework.http.client.ClientHttpResponse;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
@ -182,10 +183,16 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport {
|
||||||
public void doWithRequest(ClientHttpRequest request) throws IOException {
|
public void doWithRequest(ClientHttpRequest request) throws IOException {
|
||||||
request.getHeaders().putAll(this.headers);
|
request.getHeaders().putAll(this.headers);
|
||||||
if (this.body != null) {
|
if (this.body != null) {
|
||||||
|
if (request instanceof StreamingHttpOutputMessage) {
|
||||||
|
((StreamingHttpOutputMessage) request).setBody(outputStream ->
|
||||||
|
StreamUtils.copy(this.body, SockJsFrame.CHARSET, outputStream));
|
||||||
|
}
|
||||||
|
else {
|
||||||
StreamUtils.copy(this.body, SockJsFrame.CHARSET, request.getBody());
|
StreamUtils.copy(this.body, SockJsFrame.CHARSET, request.getBody());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits the body of an HTTP response into SockJS frames and delegates those
|
* Splits the body of an HTTP response into SockJS frames and delegates those
|
||||||
|
|
Loading…
Reference in New Issue