Skip to content

Commit 8bf128d

Browse files
committed
Do not expose accept headers in DefaultHttpRequestComposer's public API
1 parent a9bf9b2 commit 8bf128d

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

libraries/apollo-api/src/commonMain/kotlin/com/apollographql/apollo/api/http/DefaultHttpRequestComposer.kt

Lines changed: 8 additions & 23 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.Operation
88
import com.apollographql.apollo.api.Subscription
99
import com.apollographql.apollo.api.Upload
10+
import com.apollographql.apollo.api.http.DefaultHttpRequestComposer.Companion.composePostParams
1011
import com.apollographql.apollo.api.http.internal.urlEncode
1112
import com.apollographql.apollo.api.json.JsonWriter
1213
import com.apollographql.apollo.api.json.buildJsonByteString
@@ -32,14 +33,12 @@ import okio.buffer
3233
*/
3334
class DefaultHttpRequestComposer(
3435
private val serverUrl: String,
35-
private val acceptHeaderQueriesAndMutations: String = HEADER_ACCEPT_VALUE_QUERIES_AND_MUTATIONS_20220824,
36-
private val acceptHeaderSubscriptions: String = HEADER_ACCEPT_VALUE_SUBSCRIPTIONS_1_0,
36+
private val acceptHeaderQueriesAndMutations: String = HEADER_ACCEPT_VALUE_QUERIES_AND_MUTATIONS,
3737
) : HttpRequestComposer {
3838

3939
constructor(serverUrl: String) : this(
4040
serverUrl = serverUrl,
41-
acceptHeaderQueriesAndMutations = HEADER_ACCEPT_VALUE_QUERIES_AND_MUTATIONS_20220824,
42-
acceptHeaderSubscriptions = HEADER_ACCEPT_VALUE_SUBSCRIPTIONS_1_0,
41+
acceptHeaderQueriesAndMutations = HEADER_ACCEPT_VALUE_QUERIES_AND_MUTATIONS,
4342
)
4443

4544
override fun <D : Operation.Data> compose(apolloRequest: ApolloRequest<D>): HttpRequest {
@@ -48,7 +47,7 @@ class DefaultHttpRequestComposer(
4847

4948
val requestHeaders = mutableListOf<HttpHeader>().apply {
5049
if (apolloRequest.operation is Subscription<*>) {
51-
add(HttpHeader(HEADER_ACCEPT_NAME, acceptHeaderSubscriptions))
50+
add(HttpHeader(HEADER_ACCEPT_NAME, HEADER_ACCEPT_VALUE_SUBSCRIPTIONS))
5251
} else {
5352
add(HttpHeader(HEADER_ACCEPT_NAME, acceptHeaderQueriesAndMutations))
5453
}
@@ -100,25 +99,11 @@ class DefaultHttpRequestComposer(
10099
// and thus is safe to execute.
101100
// See https://www.apollographql.com/docs/apollo-server/security/cors/#preventing-cross-site-request-forgery-csrf
102101
// for details.
103-
internal val HEADER_APOLLO_REQUIRE_PREFLIGHT = "Apollo-Require-Preflight"
102+
private const val HEADER_APOLLO_REQUIRE_PREFLIGHT = "Apollo-Require-Preflight"
104103

105-
val HEADER_ACCEPT_NAME = "Accept"
106-
107-
const val HEADER_ACCEPT_VALUE_QUERIES_AND_MUTATIONS_20220824 =
108-
"multipart/mixed;deferSpec=20220824, application/graphql-response+json, application/json"
109-
110-
// TODO To be agreed upon with the router and other clients
111-
const val HEADER_ACCEPT_VALUE_QUERIES_AND_MUTATIONS_20230621 =
112-
"multipart/mixed;incrementalDeliverySpec=20230621, application/graphql-response+json, application/json"
113-
114-
const val HEADER_ACCEPT_VALUE_SUBSCRIPTIONS_1_0 =
115-
"multipart/mixed;subscriptionSpec=1.0, application/graphql-response+json, application/json"
116-
117-
@Deprecated("Use HEADER_ACCEPT_VALUE_SUBSCRIPTIONS_1_0 instead", ReplaceWith("HEADER_ACCEPT_VALUE_SUBSCRIPTIONS_1_0"))
118-
val HEADER_ACCEPT_VALUE_MULTIPART = HEADER_ACCEPT_VALUE_SUBSCRIPTIONS_1_0
119-
120-
@Deprecated("Use HEADER_ACCEPT_VALUE_QUERIES_AND_MUTATIONS_20220824 instead", ReplaceWith("HEADER_ACCEPT_VALUE_QUERIES_AND_MUTATIONS_20220824"))
121-
val HEADER_ACCEPT_VALUE_DEFER = HEADER_ACCEPT_VALUE_QUERIES_AND_MUTATIONS_20220824
104+
private const val HEADER_ACCEPT_NAME = "Accept"
105+
private const val HEADER_ACCEPT_VALUE_QUERIES_AND_MUTATIONS = "multipart/mixed;deferSpec=20220824, application/graphql-response+json, application/json"
106+
private const val HEADER_ACCEPT_VALUE_SUBSCRIPTIONS = "multipart/mixed;subscriptionSpec=1.0, application/graphql-response+json, application/json"
122107

123108
private fun <D : Operation.Data> buildGetUrl(
124109
serverUrl: String,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ private constructor(
427427
*/
428428
object Defer20220824 : IncrementalDeliveryProtocol {
429429
@ApolloInternal
430-
override val acceptHeader: String = DefaultHttpRequestComposer.HEADER_ACCEPT_VALUE_QUERIES_AND_MUTATIONS_20220824
430+
override val acceptHeader: String = "multipart/mixed;deferSpec=20220824, application/graphql-response+json, application/json"
431431

432432
@ApolloInternal
433433
override fun newIncrementalResultsMerger(): IncrementalResultsMerger = Defer20220824IncrementalResultsMerger()
@@ -440,7 +440,8 @@ private constructor(
440440
*/
441441
object GraphQL17Alpha9 : IncrementalDeliveryProtocol {
442442
@ApolloInternal
443-
override val acceptHeader: String = DefaultHttpRequestComposer.HEADER_ACCEPT_VALUE_QUERIES_AND_MUTATIONS_20230621
443+
// TODO To be agreed upon with the router and other clients
444+
override val acceptHeader: String = "multipart/mixed;incrementalDeliverySpec=20230621, application/graphql-response+json, application/json"
444445

445446
@ApolloInternal
446447
override fun newIncrementalResultsMerger(): IncrementalResultsMerger = GraphQL17Alpha9IncrementalResultsMerger()

0 commit comments

Comments
 (0)