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

Rewrite multipart functionality to use a encoding builder #877

Merged

Conversation

krainboltgreene
Copy link
Contributor

@krainboltgreene krainboltgreene commented Mar 14, 2024

The current multipart functionality doesn't work with Mint, per #763. Instead we would prefer to use a multipart library that is agnostic of the client.

@krainboltgreene krainboltgreene marked this pull request as draft March 14, 2024 00:08
@krainboltgreene
Copy link
Contributor Author

Will jump back on this tomorrow.

@princemaple
Copy link
Member

cheers!

@krainboltgreene
Copy link
Contributor Author

krainboltgreene commented Mar 14, 2024

Okay my latest work produces this result:

--> POST /avengers.com/messages HTTP/1.1
--> User-Agent: swoosh/1.16.0
--> User-Agent: swoosh/1.16.0
--> Authorization: Basic YXBpOmZha2U=
--> Host: localhost:3000
--> Content-Type: multipart/form-data; boundary="==778dc3ddca08e6d79e7efa5b11837fca=="
--> Content-Length: 10784
--> 
--> 
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> content-disposition: form-data; name="bcc"
--> 
--> beast.avengers@example.com, "Clinton Francis Barton" <hawk.eye@example.com>
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> content-disposition: form-data; name="cc"
--> 
--> thor.odinson@example.com, "Bruce Banner" <hulk.smash@example.com>
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> content-disposition: form-data; name="from"
--> 
--> "T Stark" <tony.stark@example.com>
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> content-disposition: form-data; name="html"
--> 
--> <h1>Hello</h1>
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> content-disposition: form-data; name="subject"
--> 
--> Hello, Avengers!
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> content-disposition: form-data; name="text"
--> 
--> Hello
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> content-disposition: form-data; name="to"
--> 
--> wasp.avengers@example.com, "Steve Rogers" <steve.rogers@example.com>
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> content-disposition: form-data; name="h:Reply-To"
--> 
--> office.avengers@example.com
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> content-disposition: form-data; name="h:X-Mailgun-Variables"
--> 
--> {"key":"value"}
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> 
--> attachment as data with content-type
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> content-type: text/plain
--> content-disposition: form-data; name="attachment"; filename="foo.txt"
--> 
--> attachment with filename and content-type
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> content-type: text/plain
--> content-disposition: form-data; name="inline"; filename="foo.txt"
--> 
--> attachment with file name, content-type, as inline
--> --==778dc3ddca08e6d79e7efa5b11837fca==
--> content-type: text/plain
--> content-disposition: form-data; name="inline"; filename="mix.exs"
--> 
--> defmodule Swoosh.Mixfile do
-->   use Mix.Project
{{...}}
--> end
--> 
--> --==778dc3ddca08e6d79e7efa5b11837fca==--
--> 

However the tests are still returning {:error, {500, ""}}.

@krainboltgreene
Copy link
Contributor Author

@princemaple My output, in the latest pushes, seems to be 100% to spec, yet the tests still return 500?

@princemaple
Copy link
Member

Have you tested against mailgun?

Plug.Parsers.call(conn, Plug.Parsers.init(opts)) in test/support/conn_parser.ex is failing.

@princemaple
Copy link
Member

I tested against mailgun with both hackney and finch. This PR seems to work fine. Now we just need to figure out what's wrong with the test ;)

@krainboltgreene
Copy link
Contributor Author

Ah, I see, so it's a mocking issue. Fantastic news. I'll see what I can whip up.

@krainboltgreene
Copy link
Contributor Author

** (Plug.Parsers.UnsupportedMediaTypeError) unsupported media type multipart/form-data
    (plug 1.15.3) lib/plug/parsers.ex:358: Plug.Parsers.reduce/8
    /Users/krainboltgreene/Code/krainboltgreene/swoosh/test/swoosh/adapters/mailgun_test.exs:1: (file)

Ah-ha!

@krainboltgreene
Copy link
Contributor Author

Alright, tests finally pass.

@krainboltgreene krainboltgreene marked this pull request as ready for review March 15, 2024 18:42
@princemaple princemaple merged commit c005274 into swoosh:main Mar 15, 2024
12 checks passed
@princemaple
Copy link
Member

Thanks a lot for working on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants