@@ -33,6 +33,7 @@ REBOL [
33
33
0.3.2 25-Feb-2020 "Oldes" "FIX: Properly handling chunked data"
34
34
0.3.3 25-Feb-2020 "Oldes" "FEAT: support for read/binary and write/binary to force raw data result"
35
35
0.3.4 26-Feb-2020 "Oldes" "FIX: limit input data according Content-Length (#issues/2386)"
36
+ 0.3.5 26-Oct-2020 "Oldes" "FEAT: support for read/part (using Range request with read/part/binary)"
36
37
]
37
38
]
38
39
@@ -264,7 +265,7 @@ do-request: func [
264
265
Accept-charset: "utf-8"
265
266
Accept-Encoding: "gzip,deflate"
266
267
Host: either not find [80 443 ] spec/port-id [
267
- rejoin [ form spec/host #":" spec/port-id ]
268
+ ajoin [ spec/host #":" spec/port-id ]
268
269
][
269
270
form spec/host
270
271
]
@@ -471,11 +472,9 @@ http-response-headers: construct [
471
472
Last-Modified:
472
473
]
473
474
474
- do-redirect : func [ port [port! ] new-uri [url! string! file! ] /local spec state] [
475
+ do-redirect : func [ port [port! ] new-uri [url! string! file! ] /local spec state headers ] [
475
476
spec: port/spec
476
477
state: port/state
477
-
478
- clear spec/headers
479
478
port/data: none
480
479
481
480
new-uri: as url! new-uri
@@ -514,11 +513,16 @@ do-redirect: func [port [port!] new-uri [url! string! file!] /local spec state][
514
513
return throw-http-error port {Redirect to a protocol different from HTTP or HTTPS not supported}
515
514
]
516
515
517
- ;we need to reset tcp connection here before doing a redirect
516
+ ; store original request headers
517
+ headers: spec/headers
518
+ ; we need to reset tcp connection here before doing a redirect
518
519
close port/state/connection
519
520
port/spec: spec: new-uri
520
521
port/state: none
521
522
open port
523
+ ; restore original request headers
524
+ port/spec/headers: headers
525
+ port
522
526
]
523
527
524
528
check-data : func [ port /local headers res data available out chunk-size pos trailer state conn] [
@@ -683,9 +687,14 @@ sys/make-scheme [
683
687
read : func [
684
688
port [port! ]
685
689
/binary
690
+ /part length [number! ]
686
691
/local result
687
692
] [
688
693
sys/log/debug 'HTTP "READ"
694
+ unless port/state [open port port/state/close?: yes]
695
+ if all [part binary length > 0 ] [
696
+ append port/spec/headers compose [Range: (join "bytes=0-" (to integer! length) - 1 )]
697
+ ]
689
698
either any-function? : port/awake [
690
699
unless open? port [cause-error 'Access 'not-open port/spec/ref ]
691
700
if port/state/state <> 'ready [throw-http-error "Port not ready" ]
@@ -694,6 +703,7 @@ sys/make-scheme [
694
703
][
695
704
result: sync-op port []
696
705
unless binary [decode-result result]
706
+ if all [part result/2 ] [ clear skip result/2 length ]
697
707
result/2
698
708
]
699
709
]
0 commit comments