rebol - 使用 READ/PART 或 READ/SEEK 从 url 部分读取

标签 rebol rebol3

通过 HTTP Range header 部分读取对我来说效果很好:

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 中有效。)

最佳答案

从源码中可以看到

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 "

关于rebol - 使用 READ/PART 或 READ/SEEK 从 url 部分读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24401052/

相关文章:

rebol - 使用 Rebol 将二进制数据打印到 stdout

url-routing - Rebol 3 方案中的用户/密码

Rebol 快速入门

user-interface - 红色语言可执行文件也打开控制台

rebol - 如何访问 REBOL header ?

rebol - REBOL 中的多行语句?

string - 如何将 Rebol 错误格式化为字符串?

windows - 查看布局 rebol 3 不工作

reflection - Rebol为什么不换新线?类似地对待换行关键字和换行符吗?

rebol - 仅返回对象词,但不返回以冒号作为后缀定义的函数