Sha256: 2c5e91ddb5dbc4b7aef79fe0ef5a728ab24ab2f0f90fe4a385a7fdd7ef32c0e5

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Standard
      module RequestParams
        module Utils
          module HTTP
            module Request
              ##
              # TODO: Specs.
              #
              class ParseBody < Support::Command
                attr_reader :http_string

                def initialize(http_string:)
                  @http_string = http_string
                end

                ##
                # IMPORTANT: Make sure length is set in `http_string`.
                #
                # - https://stackoverflow.com/a/17599778/12201472
                # - https://github.com/ruby/webrick/blob/v1.7.0/lib/webrick/httprequest.rb
                #
                def call
                  webrick_request = ::WEBrick::HTTPRequest.new(::WEBrick::Config::HTTP)

                  webrick_request.parse(::StringIO.new(http_string))

                  webrick_request.body
                rescue ::WEBrick::HTTPStatus::BadRequest
                  nil
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
convenient_service-0.12.0 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb
convenient_service-0.11.0 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb
convenient_service-0.10.1 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb
convenient_service-0.10.0 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb
convenient_service-0.9.0 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb
convenient_service-0.8.0 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb
convenient_service-0.7.0 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb
convenient_service-0.6.0 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb