Sha256: e16e01952a24f591928cea9fb20c3e6f3ebc617d40eb023bb77a1a7d9588a522

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Standard
      class RequestParams
        module Utils
          module HTTP
            module Request
              ##
              # TODO: Specs.
              #
              class ParseBody < ConvenientService::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

5 entries across 5 versions & 1 rubygems

Version Path
convenient_service-0.17.0 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb
convenient_service-0.16.0 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb
convenient_service-0.15.0 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb
convenient_service-0.14.0 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb
convenient_service-0.13.0 lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb