Skip to content
Browse files

Allow the user to specify or omit the User-Agent header

  • Loading branch information...
1 parent 4e93b61 commit 50f6cfeb66ae3739197c8108d172d4933b457d49 @gdb committed Oct 9, 2012
Showing with 3 additions and 2 deletions.
  1. +1 −1 lib/em-http/client.rb
  2. +2 −1 lib/em-http/http_client_options.rb
View
2 lib/em-http/client.rb
@@ -154,7 +154,7 @@ def build_request
head['host'] ||= encode_host
# Set the User-Agent if it hasn't been specified
- head['user-agent'] ||= "EventMachine HttpClient"
+ head['user-agent'] ||= @req.user_agent if @req.user_agent
# Set the auth from the URI if given
head['Authorization'] = @req.uri.userinfo.split(/:/, 2) if @req.uri.userinfo
View
3 lib/em-http/http_client_options.rb
@@ -1,7 +1,7 @@
class HttpClientOptions
attr_reader :uri, :method, :host, :port
attr_reader :headers, :file, :body, :query, :path
- attr_reader :keepalive, :pass_cookies, :decoding
+ attr_reader :keepalive, :pass_cookies, :decoding, :user_agent
attr_accessor :followed, :redirects
@@ -20,6 +20,7 @@ def initialize(uri, options, method)
@pass_cookies = options.fetch(:pass_cookies, true) # pass cookies between redirects
@decoding = options.fetch(:decoding, true) # auto-decode compressed response
+ @user_agent = options.fetch(:user_agent, "EventMachine HttpClient") # set the user agent (pass nil to omit)
set_uri(uri)
end

0 comments on commit 50f6cfe

Please sign in to comment.
Something went wrong with that request. Please try again.