class VarnishClient::Request
Attributes
request[RW]
uri[RW]
Public Class Methods
new()
click to toggle source
Initialize a VarnishClient::Request
object.
# 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
Public Instance Methods
headers()
click to toggle source
Get the request headers.
# File lib/varnishclient/request.rb, line 32 def headers @request_headers end
host()
click to toggle source
Get the Host header for the request.
# File lib/varnishclient/request.rb, line 37 def host @request['Host'] end
host=(host_header)
click to toggle source
Set the Host header for the request.
# 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()
click to toggle source
Make the HTTP request.
# File lib/varnishclient/request.rb, line 82 def make_request response = @http.request(@request) end
path()
click to toggle source
Get the path of the request.
# File lib/varnishclient/request.rb, line 48 def path @uri.request_uri end
path=(path)
click to toggle source
Set the path of the request.
# 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()
click to toggle source
Get the port of the request.
# File lib/varnishclient/request.rb, line 59 def port @uri.port end
port=(port)
click to toggle source
Set the port of the request.
# 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()
click to toggle source
Get the User-Agent header.
# File lib/varnishclient/request.rb, line 71 def user_agent @request['User-Agent'] end
user_agent=(user_agent)
click to toggle source
Set the User-Agent header.
# 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