http
http copied to clipboard
Fixed #277, allow multiple fields of the same name in multipart request
Converted the fields Map to List of MapEntry objects
@kevmoo @jakemac53
Sadly this looks like it will break existing API. Is there a better way of approaching this that won't?
Thanks
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?
If we do anything here a
List<MapEntry<String, String>>would not be my choice for API. EitherMap<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.
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
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.
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'];
@mit-mit @jonasfj - can you triage and make a decision on whether we want a breaking change for this use case?
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.
Since this hasn't been touched in 4 years, I'm going to close this.