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");
|
||||
* 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.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.StreamingHttpOutputMessage;
|
||||
import org.springframework.http.client.ClientHttpRequest;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
@ -182,7 +183,13 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport {
|
|||
public void doWithRequest(ClientHttpRequest request) throws IOException {
|
||||
request.getHeaders().putAll(this.headers);
|
||||
if (this.body != null) {
|
||||
StreamUtils.copy(this.body, SockJsFrame.CHARSET, request.getBody());
|
||||
if (request instanceof StreamingHttpOutputMessage) {
|
||||
((StreamingHttpOutputMessage) request).setBody(outputStream ->
|
||||
StreamUtils.copy(this.body, SockJsFrame.CHARSET, outputStream));
|
||||
}
|
||||
else {
|
||||
StreamUtils.copy(this.body, SockJsFrame.CHARSET, request.getBody());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue