Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path.asByteStream() calculates incorrect content length unless endInclusive is specified #678

Closed
ianbotsf opened this issue Jul 26, 2022 · 0 comments · Fixed by #698
Closed
Assignees
Labels
bug This issue is a bug.

Comments

@ianbotsf
Copy link
Contributor

Describe the bug

When using the extension method Path.asByteStream() to get a streaming body, the endInclusive parameter must be specified otherwise the content length is incorrectly calculated. The -1 default is passed through to the File.asByteStream() method which in turn passes it to FileContent where its meaning is lost, leading to content lengths of 0 bytes.

This causes streaming bodies to have incorrect lengths calculated leading to errors like:

Exception in thread "main" java.net.ProtocolException: expected 0 bytes but received 8192
	at okhttp3.internal.connection.Exchange$RequestBodySink.write(Exchange.kt:219)
	at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.kt:255)
	at okio.RealBufferedSink.write(RealBufferedSink.kt:88)
	at aws.smithy.kotlin.runtime.http.engine.okhttp.ByteChannelRequestBody$writeTo$1.invokeSuspend(ByteChannelRequestBody.kt:51)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:284)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at aws.smithy.kotlin.runtime.http.engine.okhttp.ByteChannelRequestBody.writeTo(ByteChannelRequestBody.kt:41)
	at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:62)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:84)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:65)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:205)
	at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:533)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Expected Behavior

Path.asByteStream() should work properly even with no endInclusive parameter specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant