Class: VcrStripeWebhook::Server::RequestParser
- Inherits:
-
Object
- Object
- VcrStripeWebhook::Server::RequestParser
- Defined in:
- lib/vcr_stripe_webhook/server.rb
Constant Summary collapse
- MAX_HEADER_LENGTH =
16 * 1024
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #content_length ⇒ Object
- #content_type ⇒ Object
-
#initialize(socket) ⇒ RequestParser
constructor
A new instance of RequestParser.
- #json? ⇒ Boolean
- #json_value ⇒ Object
Constructor Details
#initialize(socket) ⇒ RequestParser
Returns a new instance of RequestParser.
70 71 72 73 74 75 76 |
# File 'lib/vcr_stripe_webhook/server.rb', line 70 def initialize(socket) @method, @path = read_start_line(socket) @headers = read_headers(socket) return unless content_length @body = socket.read(content_length) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
68 69 70 |
# File 'lib/vcr_stripe_webhook/server.rb', line 68 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
68 69 70 |
# File 'lib/vcr_stripe_webhook/server.rb', line 68 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
68 69 70 |
# File 'lib/vcr_stripe_webhook/server.rb', line 68 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
68 69 70 |
# File 'lib/vcr_stripe_webhook/server.rb', line 68 def path @path end |
Instance Method Details
#content_length ⇒ Object
78 79 80 |
# File 'lib/vcr_stripe_webhook/server.rb', line 78 def content_length @content_length ||= headers["content-length"]&.to_i end |
#content_type ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/vcr_stripe_webhook/server.rb', line 82 def content_type return @content_type if defined?(@content_type) if headers["content-type"] @content_type, _attributes = headers["content-type"].split(/;\s+/, 2) else @content_type = nil end @content_type end |
#json? ⇒ Boolean
93 94 95 |
# File 'lib/vcr_stripe_webhook/server.rb', line 93 def json? content_type == "application/json" end |
#json_value ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/vcr_stripe_webhook/server.rb', line 97 def json_value return @json_value if defined?(@json_value) @json_value = if json? begin JSON.parse(@body) rescue StandardError nil end end end |