Skip to content

Where application/x-www-form-urlencoded and multipart/form-data? #439

@AlexeyMatskevich

Description

@AlexeyMatskevich

I'm trying to contribute to the rspec-openapi library and I'm using hanami 2 in production. In rspec-openapi, there is a dummy test application on rails that I am trying to re-implementon hanami.

In particular, the original application in some cases transmits data in the following formats: application/x-www-form-urlencoded and multipart/form-data when upload images.

I'm reading this article https://guides.hanamirb.org/v2.1/actions/formats-and-mime-types/ and I'm following this link over 50 of the most common MIME types and I can't find the MIME-type I need in the list.

By default I'm using form :json, so I'm trying to get around the problem manually:

module HanamiTest

  class App < Hanami::App
    config.actions.formats.add(:form, "application/x-www-form-urlencoded")
    config.actions.formats.add(:multipart, "multipart/form-data")
    config.actions.format :json, :form, :multipart
  end
end

But I only succeed with form data.

I researched Hanami::Action::Mime.accepted_mime_type?

        def accepted_mime_type?(mime_type, config)
          accepted_mime_types(config).any? { |accepted_mime_type|
            ::Rack::Mime.match?(mime_type, accepted_mime_type)
          }
        end

i get

irb(Hanami::Action::Mime):001:0> mime_type
=> "multipart/form-data; boundary=----------XnJLe9ZIbbGUYtzPQJ16u1"
irb(Hanami::Action::Mime):002:0> accepted_mime_types(config)
=> ["multipart/form-data"]

I also found this code for FormParser but couldn't find any documentation for it and have no idea how to use it.

Any help would be appreciated.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions