File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ type PersistedQuery struct {
22
22
}
23
23
24
24
func ParseRequestPayload (r * http.Request ) ([]RequestData , error ) {
25
+ if r .ContentLength < 1 {
26
+ return []RequestData {}, nil
27
+ }
28
+
25
29
body , err := io .ReadAll (r .Body )
26
30
if err != nil {
27
31
return []RequestData {}, err
Original file line number Diff line number Diff line change @@ -97,6 +97,16 @@ func TestParseRequestPayload(t *testing.T) {
97
97
},
98
98
wantErr : false ,
99
99
},
100
+ {
101
+ name : "Handles request without body gracefully" ,
102
+ args : args {
103
+ r : func () * http.Request {
104
+ return httptest .NewRequest ("POST" , "/graphql" , nil )
105
+ }(),
106
+ },
107
+ want : []RequestData {},
108
+ wantErr : false ,
109
+ },
100
110
}
101
111
for _ , tt := range tests {
102
112
t .Run (tt .name , func (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments