@@ -13,6 +13,7 @@ import org.springframework.mock.web.MockHttpServletResponse
1313import spock.lang.Shared
1414import spock.lang.Specification
1515
16+ import java.nio.charset.StandardCharsets
1617import java.util.concurrent.CountDownLatch
1718import java.util.concurrent.TimeUnit
1819import java.util.concurrent.atomic.AtomicReference
@@ -108,10 +109,24 @@ class AbstractGraphQLHttpServletSpec extends Specification {
108109 then :
109110 response. getStatus() == STATUS_OK
110111 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
112113 getResponseContent(). data. echo == " test"
113114 }
114115
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+
115130 def " async query over HTTP GET starts async request" () {
116131 setup :
117132 servlet = TestUtils . createDefaultServlet({ env -> env. arguments. arg }, { env -> env. arguments. arg }, { env ->
@@ -213,6 +228,21 @@ class AbstractGraphQLHttpServletSpec extends Specification {
213228 getBatchedResponseContent()[1 ]. data. echo == " test"
214229 }
215230
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+
216246 def " batched query over HTTP GET with variables returns data" () {
217247 setup :
218248 request. addParameter(' query' , ' [{ "query": "query { echo(arg:\\ "test\\ ") }", "variables": { "arg": "test" } }, { "query": "query { echo(arg:\\ "test\\ ") }", "variables": { "arg": "test" } }]' )
0 commit comments