Class: Elasticshell::Commands::Request::Parser
- Inherits:
-
Object
- Object
- Elasticshell::Commands::Request::Parser
- Includes:
- RecognizesVerb
- Defined in:
- lib/elasticshell/commands/request_parser.rb
Constant Summary
Constants included from RecognizesVerb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#command ⇒ Object
Returns the value of attribute command.
-
#path ⇒ Object
Returns the value of attribute path.
-
#query_options ⇒ Object
Returns the value of attribute query_options.
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#raw_body ⇒ Object
Returns the value of attribute raw_body.
-
#raw_path ⇒ Object
Returns the value of attribute raw_path.
-
#request_string ⇒ Object
Returns the value of attribute request_string.
-
#verb ⇒ Object
Returns the value of attribute verb.
Instance Method Summary collapse
- #construct_body! ⇒ Object
-
#initialize(command) ⇒ Parser
constructor
A new instance of Parser.
- #interpret_path! ⇒ Object
- #parse! ⇒ Object
- #request ⇒ Object
- #split_path_and_body! ⇒ Object
- #split_verb_and_request! ⇒ Object
- #strip_redirect! ⇒ Object
Methods included from RecognizesVerb
#canonicalize_verb, #is_http_verb?, #verb_re
Constructor Details
#initialize(command) ⇒ Parser
Returns a new instance of Parser.
11 12 13 |
# File 'lib/elasticshell/commands/request_parser.rb', line 11 def initialize(command) self.command = command end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
9 10 11 |
# File 'lib/elasticshell/commands/request_parser.rb', line 9 def body @body end |
#command ⇒ Object
Returns the value of attribute command.
9 10 11 |
# File 'lib/elasticshell/commands/request_parser.rb', line 9 def command @command end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/elasticshell/commands/request_parser.rb', line 9 def path @path end |
#query_options ⇒ Object
Returns the value of attribute query_options.
9 10 11 |
# File 'lib/elasticshell/commands/request_parser.rb', line 9 def @query_options end |
#raw ⇒ Object
Returns the value of attribute raw.
9 10 11 |
# File 'lib/elasticshell/commands/request_parser.rb', line 9 def raw @raw end |
#raw_body ⇒ Object
Returns the value of attribute raw_body.
9 10 11 |
# File 'lib/elasticshell/commands/request_parser.rb', line 9 def raw_body @raw_body end |
#raw_path ⇒ Object
Returns the value of attribute raw_path.
9 10 11 |
# File 'lib/elasticshell/commands/request_parser.rb', line 9 def raw_path @raw_path end |
#request_string ⇒ Object
Returns the value of attribute request_string.
9 10 11 |
# File 'lib/elasticshell/commands/request_parser.rb', line 9 def request_string @request_string end |
#verb ⇒ Object
Returns the value of attribute verb.
9 10 11 |
# File 'lib/elasticshell/commands/request_parser.rb', line 9 def verb @verb end |
Instance Method Details
#construct_body! ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/elasticshell/commands/request_parser.rb', line 54 def construct_body! self.body = case when raw_body.nil? '' when raw_body == '-' Elasticshell.info("Reading request body from STDIN. Press `C-d' to terminate input...") command.shell.input_stream.gets(nil) when File.exist?(raw_body) File.read(raw_body) else raw_body end end |
#interpret_path! ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/elasticshell/commands/request_parser.rb', line 44 def interpret_path! relative_path, query_string = raw_path.split('?') self.path = File.(relative_path, command.shell.scope.path) self. = {} URI.decode_www_form(query_string || '').each do |k, v| self.[k] = v end end |
#parse! ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/elasticshell/commands/request_parser.rb', line 20 def parse! strip_redirect! split_verb_and_request! split_path_and_body! interpret_path! construct_body! end |
#request ⇒ Object
15 16 17 18 |
# File 'lib/elasticshell/commands/request_parser.rb', line 15 def request parse! { :verb => verb, :path => path, :query_options => , :body => body } end |
#split_path_and_body! ⇒ Object
40 41 42 |
# File 'lib/elasticshell/commands/request_parser.rb', line 40 def split_path_and_body! self.raw_path, self.raw_body = request_string.split(/ /, 2) end |
#split_verb_and_request! ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/elasticshell/commands/request_parser.rb', line 32 def split_verb_and_request! if raw =~ Regexp.new("^(#{verb_re})\s+(.+)$", true) self.verb, self.request_string = canonicalize_verb($1), $2 else self.verb, self.request_string = command.shell.verb, raw end end |
#strip_redirect! ⇒ Object
28 29 30 |
# File 'lib/elasticshell/commands/request_parser.rb', line 28 def strip_redirect! self.raw = command.shell.input.gsub(/ (?:\||>).*$/,'') end |