使用READ / PART或READ / SEEK从URL进行部分读取

时间:2014-06-25 05:46:04

标签: rebol rebol3

通过HTTP Range标题进行部分阅读对我来说很好:

rebol []
client: open tcp://www.apache.org/

client/awake: func [event /local port] [
    port: event/port
    switch event/type [
        lookup [open port]
        connect [
            write port rejoin [
                {GET / HTTP/1.1} crlf
                {User-Agent: curl/7.26.0} crlf
                {Host: www.apache.org} crlf
                {Accept: */*} crlf
                {Range: bytes=0-9} crlf
                crlf
            ]
        ]
        wrote [read port]
        read [
            probe to-string port/data
            probe length? port/data
            clear port/data
        ]        
    ]
    false
]

wait [client 3]
close client
print "Done"

我想我可以使用READ / PART做同样的事情:

length? read/part http://www.apache.org/ 10   ;40195
length? read http://www.apache.org/           ;40195

但它确实有效,仍然可以获得所有字节。与READ/SEEK相同。 那是为什么? (顺便说一句,它适用于Rebol2。)

2 个答案:

答案 0 :(得分:2)

你可以从源头看到

https://github.com/rebol/rebol/blob/master/src/mezz/prot-http.r#L424

read actor没有定义任何细化。这并不意味着它们无法定义,但目前尚未就是否应该通过使用细化或使用查询方言做出决定。

您可以通过设置trace/net on来查看它在Rebol2中伪造它

>> trace/net on
>> read/part http://www.apache.org 10
URL Parse: none none www.apache.org none none none
Net-log: ["Opening" "tcp" "for" "HTTP"]
connecting to: www.apache.org
Net-log: {GET / HTTP/1.0
Accept: */*
Connection: close
User-Agent: REBOL View 2.7.8.3.1
Host: www.apache.org
}
Net-log: "HTTP/1.1 200 OK"
Net-log: ["low level read of " 2048 "bytes"]
Net-log: ["low level read of " 2048 "bytes"]
.. many lines removed
Net-log: ["low level read of " 2048 "bytes"]
Net-log: ["low level read of " 2048 "bytes"]
Net-log: ["low level read of " 2048 "bytes"]
== "<!DOCTYPE "

答案 1 :(得分:0)

可以肯定的是,它并没有在当前版本的HTTP方案中实现。还有其他缺失的部分,比如重定向,所以我认为它还不支持。