Class: HttpRequestParams
- Inherits:
-
Hash
- Object
- Hash
- HttpRequestParams
- Defined in:
- lib/http_request.rb
Overview
from Rack, parsing parameters for the Digest auth
Constant Summary collapse
- UNQUOTED =
['qop', 'nc', 'stale']
Class Method Summary collapse
-
.dequote(str) ⇒ Object
From WEBrick::HTTPUtils.
- .parse(str) ⇒ Object
- .split_header_value(str) ⇒ Object
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
-
#initialize {|_self| ... } ⇒ HttpRequestParams
constructor
A new instance of HttpRequestParams.
-
#quote(str) ⇒ Object
From WEBrick::HTTPUtils.
- #to_s ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ HttpRequestParams
Returns a new instance of HttpRequestParams.
525 526 527 528 529 |
# File 'lib/http_request.rb', line 525 def initialize super yield self if block_given? end |
Class Method Details
.dequote(str) ⇒ Object
From WEBrick::HTTPUtils
515 516 517 518 519 |
# File 'lib/http_request.rb', line 515 def self.dequote(str) # From WEBrick::HTTPUtils ret = (/\A"(.*)"\Z/ =~ str) ? $1 : str.dup ret.gsub!(/\\(.)/, "\\1") ret end |
.parse(str) ⇒ Object
507 508 509 510 511 512 513 |
# File 'lib/http_request.rb', line 507 def self.parse(str) split_header_value(str).inject(new) do |header, param| k, v = param.split('=', 2) header[k] = dequote(v) header end end |
.split_header_value(str) ⇒ Object
521 522 523 |
# File 'lib/http_request.rb', line 521 def self.split_header_value(str) str.scan( /(\w+\=(?:"[^\"]+"|[^,]+))/n ).collect{ |v| v[0] } end |
Instance Method Details
#[](k) ⇒ Object
531 532 533 |
# File 'lib/http_request.rb', line 531 def [](k) super k.to_s end |
#[]=(k, v) ⇒ Object
535 536 537 |
# File 'lib/http_request.rb', line 535 def []=(k, v) super k.to_s, v.to_s end |
#quote(str) ⇒ Object
From WEBrick::HTTPUtils
548 549 550 |
# File 'lib/http_request.rb', line 548 def quote(str) # From WEBrick::HTTPUtils '"' << str.gsub(/[\\\"]/o, "\\\1") << '"' end |
#to_s ⇒ Object
541 542 543 544 545 546 |
# File 'lib/http_request.rb', line 541 def to_s inject([]) do |parts, (k, v)| parts << "#{k}=" + (UNQUOTED.include?(k) ? v.to_s : quote(v)) parts end.join(', ') end |