4

I can perform a HEAD request with Faraday (Faraday.head url), but I am using Mechanize on my current project.

I would like to grab a value from the header (filename) without downloading the file. Does the Mechanize gem provide such an option? I am using v2.0.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
JP.
  • 5,536
  • 7
  • 58
  • 100

1 Answers1

6

Just like get but it's head instead:

page = agent.head 'http://www.google.com/'
page.body.length
#=> 0
page.header.keys
#=> ["date", "expires", "cache-control", "content-type", "set-cookie", "p3p", "server", "x-xss-protection", "x-frame-options", "transfer-encoding"]
pguardiario
  • 53,827
  • 19
  • 119
  • 159