Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if web file exists, without downloading it?

Tags:

ruby

Is it somehow possible to check if a file exists, without actually downloading it?

I have this large (~ 40mb) file, for example:

http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-6.0.11-0.glibc23.src.rpm

This is not strictly related to ruby, but it would be nice if the sender could set the content length.

RestClient.get "http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-6.0.11-0.glibc23.src.rpm", 
               headers: {"Content-Length" => 100}
like image 747
Linus Oleander Avatar asked Oct 04 '11 23:10

Linus Oleander


1 Answers

Try RestClient.head. (See http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4.)

like image 144
Daniel Brockman Avatar answered Oct 04 '22 11:10

Daniel Brockman