Class: VarnishClient::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/varnishclient/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequest

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

#requestObject

Returns the value of attribute request.



13
14
15
# File 'lib/varnishclient/request.rb', line 13

def request
  @request
end

#uriObject

Returns the value of attribute uri.



13
14
15
# File 'lib/varnishclient/request.rb', line 13

def uri
  @uri
end

Instance Method Details

#headersObject

Get the request headers.



32
33
34
# File 'lib/varnishclient/request.rb', line 32

def headers
  @request_headers
end

#hostObject

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_requestObject

Make the HTTP request.



82
83
84
# File 'lib/varnishclient/request.rb', line 82

def make_request
  response = @http.request(@request)
end

#pathObject

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

#portObject

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_agentObject

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