Skip to content

Use registered multipart/form-data parser#478

Merged
ahx merged 1 commit into
ahx:mainfrom
moberegger:moberegger/use-registered-multipart-form-parser
May 26, 2026
Merged

Use registered multipart/form-data parser#478
ahx merged 1 commit into
ahx:mainfrom
moberegger:moberegger/use-registered-multipart-form-parser

Conversation

@moberegger
Copy link
Copy Markdown
Contributor

@moberegger moberegger commented May 25, 2026

With the changes made in #472, openapi_first will now always use RequestBodyParsers::MultipartBodyParser to parse a multipart/form-data request. This PR makes it so that it will use the registered parser (which by default is RequestBodyParsers::MultipartBodyParser).

This is to support any custom 'multipart/form-data' parsers that may have been registered. For example, with

OpenapiFirst::RequestBodyParsers.register(
  'multipart/form-data',
  MyCustomMultipartBodyParser,
)

openapi_first will now use MyCustomMultipartBodyParser.

@moberegger moberegger requested a review from ahx as a code owner May 25, 2026 21:59
@ahx
Copy link
Copy Markdown
Owner

ahx commented May 26, 2026

Hi. Thanks for the PR. This makes the whole story about request body parsers more coherent.

This PR makes it apparent, that I got a bit lazy in #472 and vibe coded the thing, because I wanted to get the issue closed without looking more into finding a better interface that uses the same code path for content with "encoding" or without "encoding".

@ahx ahx merged commit e3b36b7 into ahx:main May 26, 2026
17 checks passed
@ahx
Copy link
Copy Markdown
Owner

ahx commented May 26, 2026

Maybe we should change the interface for parsers to always pass an arbitrary options hash like

class MyCustomMultipartBodyParser
  def initialize(options={})
  end
end

OpenapiFirst::RequestBodyParsers.register(
  'multipart/form-data',
  MyCustomMultipartBodyParser,
)

# … and internally it always calls `.new` on the class
RequestBodyParsers[content_type].new({encoding: })

This would mean an interface change from parser_class.new.call(request) to parser_class.new(options_hash).call(request).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants