0

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.

Community
  • 1
  • 1
Rebol Tutorial
  • 2,738
  • 2
  • 25
  • 36

3 Answers3

1

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

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

endo64
  • 2,269
  • 2
  • 27
  • 34
1
>> 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
  • 4,856
  • 1
  • 23
  • 41
  • 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 Jun 22 '10 at 22:14
  • By the way I found this http://www.mail-archive.com/rebol-list@rebol.com/msg09334.html but still can't see how to get the size of the file with this other method. Can I ? – Rebol Tutorial Jun 22 '10 at 22:16
  • Finally I found the other solution see other good answer below. – Rebol Tutorial Jun 22 '10 at 22:38
  • 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.html probe page/locals` – Graham Chiu Jun 22 '10 at 23:14
  • SO's parser alters my comment. It is page: open http: // rebol.com / index.html. – Graham Chiu Jun 22 '10 at 23:26
  • 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 Jun 23 '10 at 19:26
  • Just info? The open trick is good for grabbing cookies etc that are otherwise lost using a straight 'read. – Graham Chiu Jun 23 '10 at 22:02
1

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
  • 2,738
  • 2
  • 25
  • 36