Skip to content

Multipart EOF don't have \r\n at the end #197

@eminarcissus

Description

@eminarcissus

I've used HTTPosion to do some multiparts uploads with hackney but found the server didn't recognized the request, and I've done quite a lot of tests in modifying src/lib/hackney_multiparts.erl to find out which part is the real culprit, finally figure out looks like the request issues from requests(python) have a \r\n at the end of request but not for the hackney lib.
here is my modification:

line 137:
mp_eof(Boundary) ->
<<"--", Boundary/binary, "--">>.

to
mp_eof(Boundary) ->
<<"--", Boundary/binary, "--\r\n">>.

And after the change everything works like a charm, don't know which one did really follow the rfc sheet, but If I'm remembered well every sentence communication via http should have a \r\n at the end, so maybe this is a bug over here.

Also for this function
mp_file_header({file, Path, ExtraHeaders}, Boundary) ->
FName = hackney_bstr:to_binary(filename:basename(Path)),
Disposition = {<<"form-data">>,
[{<<"name">>, <<"file">>},
{<<"filename">>, <<""", FName/binary, """>>}]},
mp_file_header({file, Path, Disposition, ExtraHeaders}, Boundary);
mp_file_header({file, Path, {Disposition, Params}, ExtraHeaders}, Boundary) ->
CType = hackney_mimetypes:filename(Path),
Len = filelib:file_size(Path),
ExtraHeaders0 = lists:map(fun ({K, V}) -> {hackney_bstr:to_lower(K), V} end, ExtraHeaders),
Headers = mp_filter_header([{<<"content-type">>, CType},
{<<"content-length">>, Len}],
[{<<"content-disposition">>, Disposition, Params} | ExtraHeaders0]),
BinHeader = mp_header(Headers, Boundary),
{BinHeader, Len}.

When sending Disposiion,ExtraHeaders, Disposition kv values didn't add quote " into the disposition,although it didn't make difference to the server, but it also is a point where it differs from what I get with python.requests.

from hackney
Content-Disposition: form-data; name=file; filename=avatar.jpg

from python
Content-Disposition: form-data; name="file"; filename="avatar.jpg"

so my temporary solution is add a quote into the value of name and filename temporary to make it works as expected.

Hope those can be merged and fixed soon, really appreciate your works on this lib :)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions