Class: VarnishClient::Request
- Inherits:
-
Object
- Object
- VarnishClient::Request
- Defined in:
- lib/varnishclient/request.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
Returns the value of attribute request.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#headers ⇒ Object
Get the request headers.
-
#host ⇒ Object
Get the Host header for the request.
-
#host=(host_header) ⇒ Object
Set the Host header for the request.
-
#initialize ⇒ Request
constructor
Initialize a VarnishClient::Request object.
-
#make_request ⇒ Object
Make the HTTP request.
-
#path ⇒ Object
Get the path of the request.
-
#path=(path) ⇒ Object
Set the path of the request.
-
#port ⇒ Object
Get the port of the request.
-
#port=(port) ⇒ Object
Set the port of the request.
-
#user_agent ⇒ Object
Get the User-Agent header.
-
#user_agent=(user_agent) ⇒ Object
Set the User-Agent header.
Constructor Details
#initialize ⇒ Request
Initialize a VarnishClient::Request object.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/varnishclient/request.rb', line 15 def initialize # Set some default values. # We're running `varnishlog` on localhost. default_http_hostname = 'http://localhost' default_http_port = '80' default_request_uri = '/' @uri = URI.parse("#{default_http_hostname}:#{default_http_port}#{default_request_uri}") @http = Net::HTTP.new(@uri.host, @uri.port) @request_headers = { 'Host' => 'www.example.com', 'User-Agent' => 'shellac' } @request = Net::HTTP::Get.new(@uri.request_uri, @request_headers) end |
Instance Attribute Details
#request ⇒ Object
Returns the value of attribute request.
13 14 15 |
# File 'lib/varnishclient/request.rb', line 13 def request @request end |
#uri ⇒ Object
Returns the value of attribute uri.
13 14 15 |
# File 'lib/varnishclient/request.rb', line 13 def uri @uri end |
Instance Method Details
#headers ⇒ Object
Get the request headers.
32 33 34 |
# File 'lib/varnishclient/request.rb', line 32 def headers @request_headers end |
#host ⇒ Object
Get the Host header for the request.
37 38 39 |
# File 'lib/varnishclient/request.rb', line 37 def host @request['Host'] end |
#host=(host_header) ⇒ Object
Set the Host header for the request.
42 43 44 45 |
# File 'lib/varnishclient/request.rb', line 42 def host=(host_header) @request_headers['Host'] = host_header @request = Net::HTTP::Get.new(@uri.request_uri, @request_headers) end |
#make_request ⇒ Object
Make the HTTP request.
82 83 84 |
# File 'lib/varnishclient/request.rb', line 82 def make_request response = @http.request(@request) end |
#path ⇒ Object
Get the path of the request.
48 49 50 |
# File 'lib/varnishclient/request.rb', line 48 def path @uri.request_uri end |
#path=(path) ⇒ Object
Set the path of the request.
53 54 55 56 |
# File 'lib/varnishclient/request.rb', line 53 def path=(path) @uri.path = path @request = Net::HTTP::Get.new(@uri.request_uri, @request_headers) end |
#port ⇒ Object
Get the port of the request.
59 60 61 |
# File 'lib/varnishclient/request.rb', line 59 def port @uri.port end |
#port=(port) ⇒ Object
Set the port of the request.
64 65 66 67 68 |
# File 'lib/varnishclient/request.rb', line 64 def port=(port) @uri.port = port @http = Net::HTTP.new(@uri.host, @uri.port) @request = Net::HTTP::Get.new(@uri.request_uri, @request_headers) end |
#user_agent ⇒ Object
Get the User-Agent header.
71 72 73 |
# File 'lib/varnishclient/request.rb', line 71 def user_agent @request['User-Agent'] end |
#user_agent=(user_agent) ⇒ Object
Set the User-Agent header.
76 77 78 79 |
# File 'lib/varnishclient/request.rb', line 76 def user_agent=(user_agent) @request_headers['User-Agent'] = user_agent @request = Net::HTTP::Get.new(@uri.request_uri, @request_headers) end |