Skip to content

Instantly share code, notes, and snippets.

@cb372
Created November 3, 2013 16:59
Show Gist options
  • Save cb372/7292307 to your computer and use it in GitHub Desktop.
Save cb372/7292307 to your computer and use it in GitHub Desktop.
Trying to reproduce problem with file downloads using CasperJS. Failed to reproduce problem - User Agent and cookies are sent as expected.
// Note: Add a line to /etc/hosts before running.
// 127.0.0.1 www.oracle.com download.oracle.com
var casper = require('casper').create();
casper.userAgent('Custom user agent');
casper.start('http://www.oracle.com:4567/', function() {
this.echo('Opened page at /');
});
casper.then(function() {
this.download('http://download.oracle.com:4567/download', 'response.txt');
});
casper.run();
require 'sinatra'
get '/' do
response.set_cookie('my_cookie', :value => 'asdf',:domain => '.oracle.com')
"Hello"
end
get '/download' do
headers = request.env.select {|k,v| k.start_with? 'HTTP_'}
.collect {|pair| [pair[0].sub(/^HTTP_/, ''), pair[1]]}
.collect {|pair| pair.join(": ") << "\n"}
.sort
.join("\n")
"Here are your request headers.\n\n" + headers
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment