Browse Source

Allow repeatable writes in Client Interceptors

See gh-31449
pull/32265/head
Arjen Poutsma 2 years ago
parent
commit
b4bec4ca61
  1. 15
      spring-web/src/main/java/org/springframework/http/client/InterceptingClientHttpRequest.java

15
spring-web/src/main/java/org/springframework/http/client/InterceptingClientHttpRequest.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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 { @@ -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…
Cancel
Save