Skip to content

Refactor parser logic to better allow subclassing #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

defnull
Copy link
Owner

@defnull defnull commented Jul 7, 2025

This tries to fix #73 by moving all general purpose parser logic out of MultipartSegment back into the parser where it belongs and isolating form-data specific checks into a private parser method which can be overridden. Developers can now subclass PushMultipartParser and override _create_segment(self, headerlist) to support other multipart stream types (e.g. multipart/byterange or multipart/mixed) if necessary.

The change has a minimal impact on performance and actually performs better for the relevant use cases (large forms or large uploads).

defnull added 2 commits July 7, 2025 13:45
This patch moves segment parsing logic from private MultipartSegment methods back into the PushMultipartParser where it belongs, and isolates the 'form-data' specific checks into a single private method to allow subclasses to support different segment and steam types (e.g. multipart/byterange or multipart/mixed).

change: MultipartSegment.name is now typed as optional, but is still guaranteed to be a string for unmodified versions of the parser.
@defnull defnull changed the title Refactor parser logig to better allow subclassing Refactor parser logic to better allow subclassing Jul 7, 2025
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.

Feature request: support MultipartSegment subclasses in PushMultipartParser
1 participant