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 {
439
439
return false ;
440
440
}
441
441
442
+ final int BUFFER_LENGTH = 128 ;
442
443
ByteArrayOutputStream result = new ByteArrayOutputStream ();
443
- byte [] buffer = new byte [128 ];
444
+ byte [] buffer = new byte [BUFFER_LENGTH ];
444
445
int length ;
445
446
446
- inputStream .mark (0 );
447
+ inputStream .mark (BUFFER_LENGTH );
447
448
while ((length = inputStream .read (buffer )) != -1 ) {
448
449
result .write (buffer , 0 , length );
449
450
String chunk = result .toString ();
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ import org.springframework.mock.web.MockHttpServletResponse
13
13
import spock.lang.Shared
14
14
import spock.lang.Specification
15
15
16
+ import javax.servlet.ServletInputStream
17
+ import javax.servlet.http.HttpServletRequest
16
18
/**
17
19
* @author Andrew Potter
18
20
*/
@@ -715,4 +717,26 @@ class GraphQLServletSpec extends Specification {
715
717
expect :
716
718
servlet. getMapper(). writeValueAsString(ExecutionTypeInfo . newTypeInfo(). type(new GraphQLNonNull (Scalars.GraphQLString )). build()) != " {}"
717
719
}
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
+ }
718
742
}
You can’t perform that action at this time.
0 commit comments