File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
main/java/graphql/servlet
test/groovy/graphql/servlet Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -439,11 +439,12 @@ private boolean isBatchedQuery(InputStream inputStream) throws IOException {
439439 return false ;
440440 }
441441
442+ final int BUFFER_LENGTH = 128 ;
442443 ByteArrayOutputStream result = new ByteArrayOutputStream ();
443- byte [] buffer = new byte [128 ];
444+ byte [] buffer = new byte [BUFFER_LENGTH ];
444445 int length ;
445446
446- inputStream .mark (0 );
447+ inputStream .mark (BUFFER_LENGTH );
447448 while ((length = inputStream .read (buffer )) != -1 ) {
448449 result .write (buffer , 0 , length );
449450 String chunk = result .toString ();
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ import org.springframework.mock.web.MockHttpServletResponse
1313import spock.lang.Shared
1414import spock.lang.Specification
1515
16+ import javax.servlet.ServletInputStream
17+ import javax.servlet.http.HttpServletRequest
1618/**
1719 * @author Andrew Potter
1820 */
@@ -715,4 +717,26 @@ class GraphQLServletSpec extends Specification {
715717 expect :
716718 servlet. getMapper(). writeValueAsString(ExecutionTypeInfo . newTypeInfo(). type(new GraphQLNonNull (Scalars.GraphQLString )). build()) != " {}"
717719 }
720+
721+ def " isBatchedQuery check uses buffer length as read limit" () {
722+ setup :
723+ HttpServletRequest mockRequest = Mock ()
724+ ServletInputStream mockInputStream = Mock ()
725+
726+ mockInputStream. markSupported() >> true
727+ mockRequest. getInputStream() >> mockInputStream
728+ mockRequest. getMethod() >> " POST"
729+
730+ when :
731+ servlet. doPost(mockRequest, response)
732+
733+ then :
734+ 1 * mockInputStream. mark(128 )
735+
736+ then :
737+ 1 * mockInputStream. read({ it. length == 128 }) >> -1
738+
739+ then :
740+ 1 * mockInputStream. reset()
741+ }
718742}
You can’t perform that action at this time.
0 commit comments