http icon indicating copy to clipboard operation
http copied to clipboard

Fixed #277, allow multiple fields of the same name in multipart request

Open AfzalivE opened this issue 6 years ago • 8 comments

Converted the fields Map to List of MapEntry objects

AfzalivE avatar May 15 '19 16:05 AfzalivE

@kevmoo @jakemac53

Sadly this looks like it will break existing API. Is there a better way of approaching this that won't?

Thanks

AfzalivE avatar May 15 '19 16:05 AfzalivE

If we do anything here a List<MapEntry<String, String>> would not be my choice for API. Either Map<String, List<String>> or some kind of multimap thing would be better.

I had a hard time figuring out if the spec has anything to say about duplicated fields - from what I saw I think the Mailgun API in question should work if you use fields['action[0]']=.... Does that work for you?

natebosch avatar May 28 '19 21:05 natebosch

If we do anything here a List<MapEntry<String, String>> would not be my choice for API. Either Map<String, List<String>> or some kind of multimap thing would be better.

I had a hard time figuring out if the spec has anything to say about duplicated fields - from what I saw I think the Mailgun API in question should work if you use fields['action[0]']=.... Does that work for you?

It doesn't say anything about duplicated fields (presumably because that's supposed to work everywhere).

fields['action[0]'] just adds a field called action[0] in the payload. Not sure if that is what you're suggesting. This is what I tried:

request.fields['action[0]'] = routeData.action[0];
request.fields['action[1]'] = routeData.action[1];

Yeah, I'll try to switch this to Map<String, List<String>> instead. At least until we get an implementation of MultiMap in collections but it seems that that is stagnant for the last year.

AfzalivE avatar May 30 '19 00:05 AfzalivE

In the issue you mentioned mailgun. I found a thread that seemed to indicate they should accept requests in the action[n] format:

https://groups.google.com/d/msg/spray-user/5kSZ87OnfkE/rOzoNhzPRD0J

natebosch avatar May 31 '19 18:05 natebosch

In the issue you mentioned mailgun. I found a thread that seemed to indicate they should accept requests in the action[n] format:

https://groups.google.com/d/msg/spray-user/5kSZ87OnfkE/rOzoNhzPRD0J

I just tried postman with the action[n] format and that didn't work at all. I wouldn't be surprised if they changed things since 2013 though.

AfzalivE avatar Jun 03 '19 18:06 AfzalivE

Okay changed it back to a Map and values in the map to a list so the interface is now:

    request.fields['field1'] = ['value1', 'value2'];
    request.fields['field2'] = ['value2'];

AfzalivE avatar Jun 16 '19 15:06 AfzalivE

@mit-mit @jonasfj - can you triage and make a decision on whether we want a breaking change for this use case?

natebosch avatar Jun 17 '19 17:06 natebosch

RE: @natebosch https://github.com/dart-lang/http/pull/278#issuecomment-496700971

I had a hard time figuring out if the spec has anything to say about duplicated fields

RFC2388 says:

The relationship of the ordering of fields within a form and the ordering of returned values within "multipart/form-data" is not defined by this specification, nor is the handling of the case where a form has multiple fields with the same name.

RFC7578 follows up by saying:

Form parts with identical field names MUST NOT be coalesced.

In general form and query data encoding is more de-facto standards than hard specs.

FWIW, Chromium encodes duplicate fields in multipart/form-data:

Content-Disposition: form-data; name="myfield"
..
Content-Disposition: form-data; name="myfield"

the same way it does for application/x-www-form-urlencoded:

?myfield=val1&myfield=val2

by writing it multiple times.

ghost avatar Jun 18 '19 08:06 ghost

Since this hasn't been touched in 4 years, I'm going to close this.

AfzalivE avatar Mar 03 '23 20:03 AfzalivE