tags:

views:

44

answers:

3

I Would like the get the filesize of a remote file using Rebol, in a similar way to how it is done with php, by send an HTTP HEAD request. I can't find any example of how to do this in Rebol, but using the Prot-http module may be the right place to start?

i tried

read/custom URL [ HEAD "" ]

it returns "" and not header.

A: 

This is for R2 but you can examine the source code,

http://rebol.wik.is/Protocols/Http

endo64
I don't understand. Is it read/custom URL [ HEAD "" ] that I should use ? it returns "" and not header.
Rebol Tutorial
it's`read/custom http://www.rebol.com [ HEAD "" ]`but this just returns information as to if the page exists.
Graham Chiu
+1  A: 
>> trace/net on
>> i: info? http://www.rebol.com/index.html
URL Parse: none none www.rebol.com none none index.html
Net-log: ["Opening" "tcp" "for" "HTTP"]
connecting to: www.rebol.com
Net-log: {HEAD /index.html HTTP/1.0
Accept: */*
Connection: close
User-Agent: REBOL View 2.7.6.3.1
Host: www.rebol.com
}
Net-log: "HTTP/1.1 200 OK"
>> probe i
make object! [
    size: 7091
    date: 11-Jun-2010/21:12:49
    type: 'file
]
Graham Chiu
mucho gracias ! I typed probe info? http://mirror.bytemark.co.uk/ubuntu-releases/lucid/ubuntu-10.04-desktop-i386.iso and it gave the desired file size: 733419520
Rebol Tutorial
By the way I found this http://www.mail-archive.com/[email protected]/msg09334.html but still can't see how to get the size of the file with this other method. Can I ?
Rebol Tutorial
Finally I found the other solution see other good answer below.
Rebol Tutorial
There are lots of solutions. I just gave you the official way as it actually uses the HEAD method. :) Another way is to see the private data stored by Rebol. Eg.`page: open http://www.rebol.com/index.htmlprobe page/locals`
Graham Chiu
SO's parser alters my comment. It is page: open http: // rebol.com / index.html.
Graham Chiu
GREAT ! but for is there any option not to wait for big binary file ? I tried with http://mirror.bytemark.co.uk/ubuntu-releases/lucid/ubuntu-10.04-desktop-i386.iso and I guess it waits for downloading
Rebol Tutorial
Just info? The open trick is good for grabbing cookies etc that are otherwise lost using a straight 'read.
Graham Chiu
A: 

An other solution is

>> port: open tcp://mirror.bytemark.co.uk:80
>> insert port "HEAD /ubuntu-releases/lucid/ubuntu-10.04-desktop-i386.iso HTTP/1.1 ^/"
>> insert port "Host: mirror.bytemark.co.uk ^/^/"
>> while [data: copy port][prin data]
HTTP/1.1 200 OK
Date: Tue, 22 Jun 2010 22:36:48 GMT
Server: Apache/2.2.9 (Debian)
Last-Modified: Thu, 29 Apr 2010 12:56:31 GMT
ETag: "238046-2bb71800-4855fa7d53dc0"
Accept-Ranges: bytes
Content-Length: 733419520
Content-Type: application/x-iso9660-image

>>
Rebol Tutorial