thoughtbot/capybara-webkit — Issue #198: Setting header inserts blank line
Author: gma
Created: 2011-10-25 13:17:30+00:00
State: open

I'm trying to use capybara-webkit with basic auth. I saw ticket #69 in which @jferris suggested using the `header` method to set the request headers. Nice idea, but it doesn't seem to work. Here's my code (that lives in a `background` block in a steak test suite):

auth_string = ActiveSupport::Base64.encode64("username:password")
driver = Capybara.current_session.driver
driver.header "Authorization", "Basic #{auth_string}"

I was getting HTTP code 411 which means that the content length wasn't specified. I ran tcpdump to capture the data that was getting sent over the socket, and pulled this lump of text out of the results:

POST /weathercentre/flurries HTTP/1.1
Origin: http://127.0.0.1:52898
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/533.3 (KHTML, like Gecko) capybara-webkit Safari/533.3
Content-Type: application/x-www-form-urlencoded
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Referer: http://127.0.0.1:52898/weathercentre/flurries
Authorization: Basic bWZpc2g6aHVycmljYW5l

Content-Length: 58
Connection: Keep-Alive
Accept-Encoding: gzip
Accept-Language: en-US,*
Host: 127.0.0.1:52898

And there's the blank line.

Should I have set this header some other way? No other approach was leaping out at me.

If you want to use this technique to reproduce it, here's the command I ran:

tcpdump -A -s 64000 -i lo0 tcp

I'm using ree-1.8.7-2011.03, capybara 1.1.1 and capybara-webkit 0.7.2.