@@ -13,6 +13,7 @@ import org.springframework.mock.web.MockHttpServletResponse
13
13
import spock.lang.Shared
14
14
import spock.lang.Specification
15
15
16
+ import java.nio.charset.StandardCharsets
16
17
import java.util.concurrent.CountDownLatch
17
18
import java.util.concurrent.TimeUnit
18
19
import java.util.concurrent.atomic.AtomicReference
@@ -108,10 +109,24 @@ class AbstractGraphQLHttpServletSpec extends Specification {
108
109
then :
109
110
response. getStatus() == STATUS_OK
110
111
response. getContentType() == CONTENT_TYPE_JSON_UTF8
111
- response. getContentLength() == mapper. writeValueAsString([" data" : [" echo" : " test" ]]). length()
112
+ response. getContentLength() == mapper. writeValueAsString([" data" : [" echo" : " test" ]]). getBytes( StandardCharsets . UTF_8 ) . length
112
113
getResponseContent(). data. echo == " test"
113
114
}
114
115
116
+ def " query over HTTP GET returns data with correct contentLength" () {
117
+ setup :
118
+ request. addParameter(' query' , ' query { echo(arg:"special char á") }' )
119
+
120
+ when :
121
+ servlet. doGet(request, response)
122
+
123
+ then :
124
+ response. getStatus() == STATUS_OK
125
+ response. getContentType() == CONTENT_TYPE_JSON_UTF8
126
+ response. getContentLength() == mapper. writeValueAsString([" data" : [" echo" : " special char á" ]]). getBytes(StandardCharsets . UTF_8 ). length
127
+ getResponseContent(). data. echo == " special char á"
128
+ }
129
+
115
130
def " async query over HTTP GET starts async request" () {
116
131
setup :
117
132
servlet = TestUtils . createDefaultServlet({ env -> env. arguments. arg }, { env -> env. arguments. arg }, { env ->
@@ -213,6 +228,21 @@ class AbstractGraphQLHttpServletSpec extends Specification {
213
228
getBatchedResponseContent()[1 ]. data. echo == " test"
214
229
}
215
230
231
+ def " batched query over HTTP GET returns data with correct contentLength" () {
232
+ setup :
233
+ request. addParameter(' query' , ' [{ "query": "query { echo(arg:\\ "special char á\\ ") }" }, { "query": "query { echo(arg:\\ "test\\ ") }" }]' )
234
+
235
+ when :
236
+ servlet. doGet(request, response)
237
+
238
+ then :
239
+ response. getStatus() == STATUS_OK
240
+ response. getContentType() == CONTENT_TYPE_JSON_UTF8
241
+ response. getContentLength() == mapper. writeValueAsString([[" data" : [" echo" : " special char á" ]], [" data" : [" echo" : " test" ]]]). getBytes(StandardCharsets . UTF_8 ). length
242
+ getBatchedResponseContent()[0 ]. data. echo == " special char á"
243
+ getBatchedResponseContent()[1 ]. data. echo == " test"
244
+ }
245
+
216
246
def " batched query over HTTP GET with variables returns data" () {
217
247
setup :
218
248
request. addParameter(' query' , ' [{ "query": "query { echo(arg:\\ "test\\ ") }", "variables": { "arg": "test" } }, { "query": "query { echo(arg:\\ "test\\ ") }", "variables": { "arg": "test" } }]' )
0 commit comments