Allow repeatable writes in Client Interceptors
See gh-31449
This commit is contained in:
parent
48da9524c3
commit
b4bec4ca61
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.http.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -92,7 +93,17 @@ class InterceptingClientHttpRequest extends AbstractBufferingClientHttpRequest {
|
|||
request.getHeaders().forEach((key, value) -> delegate.getHeaders().addAll(key, value));
|
||||
if (body.length > 0) {
|
||||
if (delegate instanceof StreamingHttpOutputMessage streamingOutputMessage) {
|
||||
streamingOutputMessage.setBody(outputStream -> StreamUtils.copy(body, outputStream));
|
||||
streamingOutputMessage.setBody(new StreamingHttpOutputMessage.Body() {
|
||||
@Override
|
||||
public void writeTo(OutputStream outputStream) throws IOException {
|
||||
StreamUtils.copy(body, outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean repeatable() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
StreamUtils.copy(body, delegate.getBody());
|
||||
|
|
Loading…
Reference in New Issue