Support for multipart formdata in RequestMessage #581

Closed
opened 2025-12-29 08:30:33 +01:00 by adam · 8 comments
Owner

Originally created by @chrischu on GitHub (Mar 4, 2024).

Originally assigned to: @StefH on GitHub.

Is your feature request related to a problem? Please describe.
As far as I can tell the RequestMessage only has good support for URL-encoded form data.

Describe the solution you'd like
It would be cool if there was support for multipart form data as well (e.g. like HttpRequest.Form from .NET Core).

Describe alternatives you've considered
An alternative would be to implement the form parsing myself, which is something I'll do in the short term, but long term I would prefer if WireMock.Net had support for this pretty common content type (afaik it is still the default solution when doing large file uploads with accompanying other data).

Originally created by @chrischu on GitHub (Mar 4, 2024). Originally assigned to: @StefH on GitHub. **Is your feature request related to a problem? Please describe.** As far as I can tell the `RequestMessage` only has good support for URL-encoded form data. **Describe the solution you'd like** It would be cool if there was support for multipart form data as well (e.g. like `HttpRequest.Form` from .NET Core). **Describe alternatives you've considered** An alternative would be to implement the form parsing myself, which is something I'll do in the short term, but long term I would prefer if WireMock.Net had support for this pretty common content type (afaik it is still the default solution when doing large file uploads with accompanying other data).
adam added the question label 2025-12-29 08:30:33 +01:00
adam closed this issue 2025-12-29 08:30:33 +01:00
Author
Owner

@StefH commented on GitHub (Mar 4, 2024):

@chrischu
I think you can use https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-MimePartMatcher for that.

@StefH commented on GitHub (Mar 4, 2024): @chrischu I think you can use https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-MimePartMatcher for that.
Author
Owner

@chrischu commented on GitHub (Mar 4, 2024):

Interesting, but can I use these matchers to assert the requests that were sent?

e.g. server.LogEntries.Select(e => e.RequestMessage).HasMultipartFormData(...) or something like that?

@chrischu commented on GitHub (Mar 4, 2024): Interesting, but can I use these matchers to assert the requests that were sent? e.g. `server.LogEntries.Select(e => e.RequestMessage).HasMultipartFormData(...)` or something like that?
Author
Owner

@StefH commented on GitHub (Mar 4, 2024):

The request message contains a property object? BodyAsMimeMessage which is MimeMessage (from MimeKitLite) which you can use to verify.

@StefH commented on GitHub (Mar 4, 2024): The request message contains a property `object? BodyAsMimeMessage` which is `MimeMessage` (from MimeKitLite) which you can use to verify.
Author
Owner

@chrischu commented on GitHub (Mar 4, 2024):

Ok I was not aware that a MimeMessage is the same as multipart form data 😮

@chrischu commented on GitHub (Mar 4, 2024): Ok I was not aware that a MimeMessage is the same as multipart form data 😮
Author
Owner

@StefH commented on GitHub (Mar 6, 2024):

@chrischu Does this answer your question?

@StefH commented on GitHub (Mar 6, 2024): @chrischu Does this answer your question?
Author
Owner

@chrischu commented on GitHub (Mar 7, 2024):

Kinda, it gives me a possible workaround, but I still think that requiring users to

  • know that MimeMessage can be used to look at multipart form data
  • manually cast the object? to MimeMessage

is not really a great user experience.

@chrischu commented on GitHub (Mar 7, 2024): Kinda, it gives me a possible workaround, but I still think that requiring users to * know that MimeMessage can be used to look at multipart form data * manually cast the object? to MimeMessage is not really a great user experience.
Author
Owner

@StefH commented on GitHub (Mar 7, 2024):

I understand your points.

  1. Correct, this should be added in more detail in the wiki.
  2. The main reason that it's an object? is that the dependency on MimeKitLite is not for all frameworks. In the future I'll split the packages and projects (https://github.com/WireMock-Net/WireMock.Net/issues/1071)
@StefH commented on GitHub (Mar 7, 2024): I understand your points. 1. Correct, this should be added in more detail in the wiki. 2. The main reason that it's an `object?` is that the dependency on MimeKitLite is not for all frameworks. In the future I'll split the packages and projects (https://github.com/WireMock-Net/WireMock.Net/issues/1071)
Author
Owner

@chrischu commented on GitHub (Mar 7, 2024):

Especially the 2nd point would hint at the fact, that probably using MimeKit to parse multipart form data is not the right choice? ASP.NET Core should have stuff to parse form data (as it can parse form data by itself). Maybe it would be better to use that instead of forcing a dependency on MimeKit?

@chrischu commented on GitHub (Mar 7, 2024): Especially the 2nd point would hint at the fact, that probably using MimeKit to parse multipart form data is not the right choice? ASP.NET Core should have stuff to parse form data (as it can parse form data by itself). Maybe it would be better to use that instead of forcing a dependency on MimeKit?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#581