kemal icon indicating copy to clipboard operation
kemal copied to clipboard

Fixing exception with HTTP::FormData

Open atlantis opened this issue 5 years ago • 2 comments

Description of the Change

In crystal 0.34.0 I get "Exception: Cannot extract form-data from HTTP request: could not find boundary in Content-Type (HTTP::FormData::Error)." whenever I'm not submitting multipart forms - wonder if HTTP::FormData recently became more strict?

Here's an example of what I'm trying to do from Javascript-land:

$.ajax({type: "POST", url: $(form).attr('action'), data: $(form).serialize()})

And then here's the headers being submitted:

Request headers:
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 121
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Host: 127.0.0.1:3000
Origin: http://127.0.0.1:3000
Pragma: no-cache
Referer: http://127.0.0.1:3000/users
Sec-Fetch-Dest: empty

So there's no mention of multipart in the Content-Type.

The problem is that parse_files is called twice - once from parse_body and then again from {% for method in PARTS %}. The call from parse_body makes sure Content-Type is multipart, which is great - but then the macro calls it anyway.

All tests pass after this change.

Alternate Designs

N/A

Benefits

Normal (i.e. non-multipart) forms and JSON post bodies work again.

Possible Drawbacks

None that I can see :)

atlantis avatar May 01 '20 09:05 atlantis

Hey any chance this could be merged in? I'm having to use a custom fork and it would be great to just pull the main shard :)

atlantis avatar Jun 29 '22 22:06 atlantis

@atlantis have you tried with the latest Crystal 1.4.1 (soon 1.5.0) and Kemal master? Is there any sample code / app where we can reproduce this?

sdogruyol avatar Jun 30 '22 14:06 sdogruyol

This PR can be closed, since it's quite old and most likely outdated.

Sija avatar Apr 27 '23 22:04 Sija

Thank you @Sija

sdogruyol avatar Apr 30 '23 11:04 sdogruyol