Skip to content
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

KTOR-7596 Make multipart Content-Type check case-insensitive #4413

Merged
merged 2 commits into from
Oct 29, 2024

Conversation

osipxd
Copy link
Member

@osipxd osipxd commented Oct 18, 2024

Subsystem
Server, ktor-http-cio

Motivation
KTOR-7596 receiveMultipart fails with "IOException: Failed to parse multipart" when content-type is capitalized

Solution
Use case-insensitive check for multipart content-type

@osipxd osipxd requested a review from e5l October 18, 2024 08:55
@osipxd osipxd self-assigned this Oct 18, 2024
@osipxd osipxd force-pushed the osipxd/multipart-content-type-check branch from b9e5dd1 to 8b32a76 Compare October 18, 2024 10:21
Copy link
Member

@e5l e5l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -72,7 +71,7 @@ internal class JettyKtorHandler(
) {
try {
val contentType = request.contentType
if (contentType != null && contentType.startsWith("multipart/")) {
if (contentType != null && contentType.startsWith("multipart/", ignoreCase = true)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would extract constant here

Copy link
Member Author

@osipxd osipxd Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could add a constant ContentType.Application.TYPE. I also thought about adding an operator function contains:

public object ContentType {
    public object Application {
        public const val TYPE: String = "application"
        // ...

        public operator fun contains(contentType: CharSequence): Boolean =
            contentType.startsWith("$TYPE/", ignoreCase = true)
    }
}

And then check the content type using in:

if (contentType in ContentType.Application) { ... }

What do you think?

Copy link
Member Author

@osipxd osipxd Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make it in a separate PR (if needed)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjhham, what do you think?

Copy link
Member Author

@osipxd osipxd Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already done some experiments locally, so here you can find a draft PR: #4433
Let's discuss there

@osipxd osipxd merged commit 8c271cb into main Oct 29, 2024
11 of 14 checks passed
@osipxd osipxd deleted the osipxd/multipart-content-type-check branch October 29, 2024 09:06
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