Class: ZimbraInterceptingProxy::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, parser) ⇒ Request

Returns a new instance of Request.



7
8
9
10
11
# File 'lib/zimbra_intercepting_proxy/request.rb', line 7

def initialize(connection, parser)
  @body = connection.body
  @headers = connection.headers
  @parser = parser
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'lib/zimbra_intercepting_proxy/request.rb', line 5

def body
  @body
end

#headersObject

Returns the value of attribute headers.



5
6
7
# File 'lib/zimbra_intercepting_proxy/request.rb', line 5

def headers
  @headers
end

#parserObject

Returns the value of attribute parser.



5
6
7
# File 'lib/zimbra_intercepting_proxy/request.rb', line 5

def parser
  @parser
end

Instance Method Details

#auth_request?Boolean

Returns:

  • (Boolean)


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

def auth_request?
  @parser.http_method == "POST" && @parser.request_url == "/zimbra/" && @headers["Cookie"] = "ZM_TEST=true" && auth_request_params?
end

#auth_request_params?Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/zimbra_intercepting_proxy/request.rb', line 17

def auth_request_params?
  uri = Addressable::URI.parse("http://localhost/?#{@body}")
  uri.query_values["loginOp"] == "login"
end

#auth_usernameObject



40
41
42
43
# File 'lib/zimbra_intercepting_proxy/request.rb', line 40

def auth_username
  uri = Addressable::URI.parse("http://localhost/?#{@body}")
  uri.query_values["username"]
end

#auth_zimbraIdObject



36
37
38
# File 'lib/zimbra_intercepting_proxy/request.rb', line 36

def auth_zimbraId
  headers["Auth-User"]
end

#portObject



26
27
28
29
# File 'lib/zimbra_intercepting_proxy/request.rb', line 26

def port
  return ZimbraInterceptingProxy::Config::ROUTE_REQUEST_PORT if route_request?
  return ZimbraInterceptingProxy::Config::AUTH_REQUEST_PORT if auth_request?
end

#route_request?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/zimbra_intercepting_proxy/request.rb', line 22

def route_request?
  @parser.request_url == ZimbraInterceptingProxy::Config::ROUTE_URL
end

#user_tokenObject



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

def user_token
  return auth_username if auth_request?
  return auth_zimbraId if route_request?
end