Class: Rack::Request

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

Overview

Add a few helper methods to Rack’s Request class.

Instance Method Summary collapse

Instance Method Details

#contentObject



29
30
31
32
33
34
35
36
# File 'lib/couchproxy/request.rb', line 29

def content
  unless defined? @proxy_content
    body.rewind
    @proxy_content = body.read
    body.rewind
  end
  @proxy_content
end

#content=(body) ⇒ Object



38
39
40
41
# File 'lib/couchproxy/request.rb', line 38

def content=(body)
  @proxy_content = body
  @env['CONTENT_LENGTH'] = body.bytesize
end

#db_nameObject



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

def db_name
  parse_db_name_and_doc_id[0]
end

#doc_idObject



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

def doc_id
  parse_db_name_and_doc_id[1]
end

#json?Boolean

Returns:

  • (Boolean)


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

def json?
  if accept = @env['HTTP_ACCEPT']
    accept.tr(' ', '').split(',').include?('application/json')
  end
end

#rewrite_proxy_url(partition_num) ⇒ Object



21
22
23
# File 'lib/couchproxy/request.rb', line 21

def rewrite_proxy_url(partition_num)
  path_info.sub(/^\/#{db_name}/, "/#{db_name}_#{partition_num}")
end

#rewrite_proxy_url!(partition_num) ⇒ Object



25
26
27
# File 'lib/couchproxy/request.rb', line 25

def rewrite_proxy_url!(partition_num)
  @env['PATH_INFO'] = rewrite_proxy_url(partition_num)
end