Change signature of ResponseContext.jsonp

This commit is contained in:
Tobe O 2018-08-19 11:40:49 -04:00
parent 2855017d68
commit 696fb8dd81

View file

@ -171,18 +171,12 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
void json(value) => serialize(value, contentType: 'application/json'); void json(value) => serialize(value, contentType: 'application/json');
/// Returns a JSONP response. /// Returns a JSONP response.
///
/// You can override the [contentType] sent; by default it is `application/javascript`.
void jsonp(value, {String callbackName: "callback", MediaType contentType}) { void jsonp(value, {String callbackName: "callback", MediaType contentType}) {
if (!isOpen) throw closed(); if (!isOpen) throw closed();
write("$callbackName(${serializer(value)})"); write("$callbackName(${serializer(value)})");
this.contentType = contentType ?? new MediaType('application', 'javascript');
if (contentType != null) {
if (contentType is ContentType)
this.contentType = contentType;
else
headers['content-type'] = contentType.toString();
} else
headers['content-type'] = 'application/javascript';
end(); end();
} }