0

Am using the following link:-

https://github.com/jarib/browsermob-proxy-rb

I have tried this to pass custom header

require 'selenium/webdriver'
require 'browsermob/proxy'

server = BrowserMob::Proxy::Server.new("/path/to/downloads/browsermob-proxy/bin/browsermob-proxy") #=> #<BrowserMob::Proxy::Server:0x000001022c6ea8 ...>
server.start

proxy = server.create_proxy #=> 

proxy.headers({'test'=> 1})

But it throws error like below:-

RestClient::InternalServerError: 500 Internal Server Error
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/request.rb:230:in `process_result'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/request.rb:178:in `block in transmit'
    from /home/karunakaran/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:852:in `start'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/resource.rb:67:in `post'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/browsermob-proxy-0.2.0/lib/browsermob/proxy/client.rb:121:in `header'
    from (irb):45

How can i pass custom header using browsermob proxy for request?

Galet
  • 4,039
  • 12
  • 62
  • 119

2 Answers2

0

Did you change the sample code's path? In the code you pasted, you have:

server = BrowserMob::Proxy::Server.new("/path/to/downloads/browsermob-proxy/bin/browsermob-proxy")

The /path/to/... part should point to the actual browsermob-proxy executable.

Jason Hoetger
  • 5,650
  • 2
  • 13
  • 14
  • I have given browsermob-proxy executable only. its working without headers. How can i pass with headers. – Galet Jan 22 '15 at 05:20
0

I have passed headers key and value as a string as below and its works.

require 'selenium/webdriver'
require 'browsermob/proxy'

server = BrowserMob::Proxy::Server.new("/path/to/downloads/browsermob-proxy/bin/browsermob-proxy") #=> #<BrowserMob::Proxy::Server:0x000001022c6ea8 ...>
server.start

proxy = server.create_proxy #=> 

proxy.headers({"test"=> "1"})
Galet
  • 4,039
  • 12
  • 62
  • 119