Skip to content

Commit 0eac932

Browse files
Fix losing response headers when using batch request (#6538)
* Fix missing response header when using batch request * Update libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/BatchingHttpInterceptor.kt --------- Co-authored-by: Martin Bonnin <[email protected]>
1 parent 0fe0bf4 commit 0eac932

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/BatchingHttpInterceptor.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.apollographql.apollo.api.CustomScalarAdapters
77
import com.apollographql.apollo.api.ExecutionOptions
88
import com.apollographql.apollo.api.Operation
99
import com.apollographql.apollo.api.http.HttpBody
10+
import com.apollographql.apollo.api.http.HttpHeader
1011
import com.apollographql.apollo.api.http.HttpMethod
1112
import com.apollographql.apollo.api.http.HttpRequest
1213
import com.apollographql.apollo.api.http.HttpResponse
@@ -176,6 +177,7 @@ class BatchingHttpInterceptor @JvmOverloads constructor(
176177
.build()
177178

178179
var exception: ApolloException? = null
180+
var responseHeader = emptyList<HttpHeader>()
179181
val result = try {
180182
val response = interceptorChain!!.proceed(request)
181183
if (response.statusCode !in 200..299) {
@@ -193,6 +195,7 @@ class BatchingHttpInterceptor @JvmOverloads constructor(
193195
)
194196
}
195197
val responseBody = response.body ?: throw DefaultApolloException("null body when executing batched query")
198+
responseHeader = response.headers
196199

197200
val list = BufferedSourceJsonReader(responseBody).use { jsonReader ->
198201
// TODO: this is most likely going to transform BigNumbers into strings, not sure how much of an issue that is
@@ -235,6 +238,11 @@ class BatchingHttpInterceptor @JvmOverloads constructor(
235238
pending[index].deferred.complete(
236239
HttpResponse.Builder(statusCode = 200)
237240
.body(Buffer().write(byteString))
241+
/*
242+
* Return the global batch headers to individual responses.
243+
* This is useful for things like cache-control that rely on HTTP headers.
244+
*/
245+
.headers(responseHeader)
238246
.build()
239247
)
240248
}

0 commit comments

Comments
 (0)