@@ -212,6 +212,37 @@ func TestServe(t *testing.T) {
212212 },
213213 startTLS ,
214214 },
215+ {
216+ "https request body is not empty" ,
217+ "testdata/https.yml" ,
218+ func (t * testing.T ) {
219+ query := "SELECT SleepTimeout"
220+ buf := bytes .NewBufferString (query )
221+ req , err := http .NewRequest ("POST" , "https://127.0.0.1:8443" , buf )
222+ checkErr (t , err )
223+ req .SetBasicAuth ("default" , "qwerty" )
224+ req .Close = true
225+
226+ resp , err := tlsClient .Do (req )
227+ checkErr (t , err )
228+ if resp .StatusCode != http .StatusGatewayTimeout {
229+ t .Fatalf ("unexpected status code: %d; expected: %d" , resp .StatusCode , http .StatusGatewayTimeout )
230+ }
231+
232+ bodyBytes , err := io .ReadAll (resp .Body )
233+ if err != nil {
234+ t .Fatalf ("error while reading body from response; err: %q" , err )
235+ }
236+
237+ b := string (bodyBytes )
238+ if ! strings .Contains (b , query ) {
239+ t .Fatalf ("expected request body: %q; got: %q" , query , b )
240+ }
241+
242+ resp .Body .Close ()
243+ },
244+ startTLS ,
245+ },
215246 {
216247 "https cache with mix query source" ,
217248 "testdata/https.cache.yml" ,
@@ -1019,6 +1050,26 @@ func fakeCHHandler(w http.ResponseWriter, r *http.Request) {
10191050 w .Header ().Set ("Content-Type" , "text/plain; charset=utf-8" )
10201051 fmt .Fprint (w , b )
10211052 fmt .Fprint (w , "Ok.\n " )
1053+ case strings .Contains (q , "SELECT SleepTimeout" ):
1054+ w .WriteHeader (http .StatusGatewayTimeout )
1055+
1056+ bodyBytes , err := io .ReadAll (r .Body )
1057+ if err != nil {
1058+ fmt .Fprintf (w , "query: %s; error while reading body: %s" , query , err )
1059+ return
1060+ }
1061+
1062+ b := string (bodyBytes )
1063+ // Ensure the original request body is not empty and remains unchanged
1064+ // after it is processed by getFullQuery.
1065+ if b == "" && b != q {
1066+ fmt .Fprintf (w , "got original req body: <%s>; escaped query: <%s>" , b , q )
1067+ return
1068+ }
1069+
1070+ // execute sleep 1.5 sec
1071+ time .Sleep (1500 * time .Millisecond )
1072+ fmt .Fprint (w , b )
10221073 default :
10231074 if strings .Contains (string (query ), killQueryPattern ) {
10241075 fakeCHState .kill ()
0 commit comments