File tree 2 files changed +28
-10
lines changed
2 files changed +28
-10
lines changed Original file line number Diff line number Diff line change @@ -466,6 +466,8 @@ type HttpDoCursor struct {
466
466
// Remote network address, filled in when HTTP connection is made, IP address
467
467
RemoteAddr string
468
468
469
+ response_body []byte
470
+
469
471
columns []vtab.Column
470
472
}
471
473
@@ -531,18 +533,24 @@ func (cur *HttpDoCursor) Column(ctx vtab.Context, c int) error {
531
533
ctx .ResultText (string (buf ))
532
534
}
533
535
case "response_body" :
534
- start := time .Now ()
535
- cur .timing .BodyStart = & start
536
-
537
- body , err := ioutil .ReadAll (cur .response .Body )
538
- end := time .Now ()
539
- cur .timing .BodyEnd = & end
540
-
541
- if err != nil {
542
- ctx .ResultError (err )
536
+ if cur .response_body == nil {
537
+ start := time .Now ()
538
+ cur .timing .BodyStart = & start
539
+
540
+ body , err := ioutil .ReadAll (cur .response .Body )
541
+ end := time .Now ()
542
+ cur .timing .BodyEnd = & end
543
+
544
+ if err != nil {
545
+ ctx .ResultError (err )
546
+ } else {
547
+ ctx .ResultBlob (body )
548
+ cur .response_body = body
549
+ }
543
550
} else {
544
- ctx .ResultBlob (body )
551
+ ctx .ResultBlob (cur . response_body )
545
552
}
553
+
546
554
case "remote_address" :
547
555
ctx .ResultText (cur .RemoteAddr )
548
556
case "timings" :
Original file line number Diff line number Diff line change @@ -173,6 +173,16 @@ def test_http_get(self):
173
173
self .assertTrue (d ["remote_address" ] in ("127.0.0.1:8080" , "[::1]:8080" ))
174
174
self .assertEqual (d ["meta" ], None )
175
175
176
+ @skip_do
177
+ def test_http_get_multiple_response_body (self ):
178
+ d = db .execute ("select response_body as r1, response_body as r2 from http_get('http://localhost:8080/base64/YWxleA==')" ).fetchone ()
179
+ self .assertEqual (d ["r1" ], b"alex" )
180
+ self .assertEqual (d ["r2" ], b"alex" )
181
+
182
+ d = db .execute ("select response_body from json_each('[\" YWxleA==\" , \" YW5nZWw=\" ]') join http_get('http://localhost:8080/base64/' || value)" ).fetchall ()
183
+ self .assertEqual (d [0 ]["response_body" ], b"alex" )
184
+ self .assertEqual (d [1 ]["response_body" ], b"angel" )
185
+
176
186
@skip_do
177
187
def test_http_get_body (self ):
178
188
d , = db .execute ("""
You can’t perform that action at this time.
0 commit comments