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

Don't explicitly set Content-Type on multipart/form-data requests #763

Merged

Conversation

sbrunk
Copy link
Contributor

@sbrunk sbrunk commented Nov 22, 2020

This came up in softwaremill/tapir#860

Before submitting pull request:

  • Check if the project compiles by running sbt compile
  • Verify docs compilation by running sbt compileDocs
  • Check if tests pass by running sbt test
  • Format code by running sbt scalafmt

request.headers.foreach { case header @ Header(name, value) =>
// for multipart/form-data requests dom.FormData is responsible for setting the Content-Type header
// as it will also compute and set the boundary for the different parts, so we have to leave it out here
if (header != Header.contentType(MediaType.MultipartFormData)) rheaders.set(name, value)
Copy link
Member

Choose a reason for hiding this comment

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

  1. There's a Headers.is(String) method for a case-insensitive check of the header's name - we probably should use it here
  2. I was wondering why no tests failed before :) And looking closer, there's a send a multipart message with custom content type test which is disabled for Scala.JS (see FetchHttpTest). Maybe we should add another test, which explicitly sets the content-type header to MultipartFormData (+ a multipart body)?
  3. Shouldn't we ignore all multipart content-type headers for scala.js? That is, just looking at the value's prefix, if it's not multipart/ Or maybe if the content-type is set to something different than multipart/form-data (which we are able to support), we should throw an exception - as we can't send a request which has e.g. multipart/mixed set. An exception is not nice, but maybe better than silently filtering things out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just pushed an update that should address your remarks. I went with your suggestion of throwing an exception for multipart types other than multipart/form-data This is also consistent with the behaviour in case of unsupported streaming bodies.

@sbrunk sbrunk force-pushed the dont-set-content-type-for-form-data branch from 7c8a82e to a2238e3 Compare November 23, 2020 21:56
@adamw adamw merged commit 2011559 into softwaremill:master Nov 24, 2020
@adamw
Copy link
Member

adamw commented Nov 24, 2020

Thanks! Released in v3.0.0-RC10

@sbrunk sbrunk deleted the dont-set-content-type-for-form-data branch November 24, 2020 20:41
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