-
Notifications
You must be signed in to change notification settings - Fork 655
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
Uploads should be read only once even when logging #4125
Conversation
…eter to not log the request's body
✅ Deploy Preview for apollo-android-docs canceled.
|
* This would be the case when reading the source of data consumes it, for instance when uploading files. | ||
*/ | ||
val isOneShot: Boolean | ||
get() = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this too much. That one more API that's useful to a small portion of the usecases but accounts for 25% of the interface. It also introduce default methods, which is something I'm never sure how backward compatible it is.
Instead, I'd much rather fail early in DefaultUpload
if the body has been transmitted already.
* be fully loaded into memory, which may cause OutOfMemoryErrors. | ||
*/ | ||
class LoggingInterceptor( | ||
private val logRequestBody: Boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a level
, like in OkHttp?
@@ -51,6 +52,10 @@ actual class DefaultHttpEngine constructor( | |||
|
|||
override fun contentLength() = body.contentLength | |||
|
|||
// This prevents OkHttp from reading the body several times (e.g. when using its logging interceptor) | |||
// which could consume files when using Uploads | |||
override fun isOneShot() = body is UploadsHttpBody |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit hacky...
apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/DefaultUpload.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor comment. LGTM otherwise. Sorry for the delay reviewing this!
…/DefaultUpload.kt Co-authored-by: Martin Bonnin <[email protected]>
In this PR, 2 commits:
isOneShot
field toHttpBody
, and use it with with the OkHttp engine. This makes using OkHttp's log interceptor not break UploadsPretty sure 2. is a breaking change, but I still wanted to see where it takes us. (I can think of a hack to still pass the option to OkHttp without adding the field to the interface)
See also #4054