From 597e55429c5141996e2aab76bfdb8c05cb075eb5 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Mon, 9 Dec 2024 23:01:34 +0300 Subject: [PATCH] Use content length to set a mark before attempting the reset --- .../java/com/microsoft/kiota/http/OkHttpRequestAdapter.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java index 7083b364..69b7b804 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java @@ -902,9 +902,15 @@ public long contentLength() throws IOException { @Override public void writeTo(@Nonnull BufferedSink sink) throws IOException { + // stored in variable before writing to the sink due to + // available()'s definition + long contentLength = contentLength(); sink.writeAll(Okio.source(requestInfo.content)); if (!isOneShot()) { try { + if (contentLength > 0) { + requestInfo.content.mark((int) contentLength); + } requestInfo.content.reset(); } catch (Exception ex) { spanForAttributes.recordException(ex);