Commit 84fa559e authored by jsbell@chromium.org's avatar jsbell@chromium.org

Service Workers/Fetch: Fix Response constructor for empty/null

The fetch spec[1] has the body parameter of the Response constructor
marked optional, and none of the accepted types are nullable. In contrast,
the Blink implementation supported passing null but required an argument.
Make the impl match the spec.

[1] https://fetch.spec.whatwg.org

BUG=412027

Review URL: https://codereview.chromium.org/701683005

git-svn-id: svn://svn.chromium.org/blink/trunk@185051 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent e2693500
......@@ -12,7 +12,7 @@ function handleReferrer(event) {
}
function handleNullBody(event) {
event.respondWith(new Response(null));
event.respondWith(new Response());
}
function handleFetch(event) {
......
......@@ -101,3 +101,32 @@ promise_test(function() {
'Response clone response body text should match.');
});
}, 'Behavior of bodyUsed in Response and clone behavior.');
promise_test(function() {
var response = new Response(null);
assert_equals(
response.headers.get('Content-Type'),
'text/plain;charset=UTF-8',
'A Response constructed with a value coerced to string should have a ' +
'text Content-Type.');
return response.text()
.then(function(text) {
assert_equals(text, 'null',
'A null value passed to Response constructor should ' +
'be coerced to the string "null".');
});
}, 'Behavior of Response passed null for body.');
promise_test(function() {
var response = new Response();
assert_equals(
response.headers.get('Content-Type'),
null,
'A Response constructed with no body should have no Content-Type.');
return response.text()
.then(function(text) {
assert_equals(text, '',
'Response with no body accessed as text should ' +
'resolve to the empty string.');
});
}, 'Behavior of Response with no body.');
......@@ -59,8 +59,14 @@ FetchResponseData* createFetchResponseDataFromWebResponse(const WebServiceWorker
}
Response* Response::create(ExecutionContext* context, ExceptionState& exceptionState)
{
return create(context, nullptr, ResponseInit(), exceptionState);
}
Response* Response::create(ExecutionContext* context, Blob* body, const Dictionary& responseInit, ExceptionState& exceptionState)
{
ASSERT(body);
return create(context, body, ResponseInit(responseInit, exceptionState), exceptionState);
}
......
......@@ -26,10 +26,13 @@ class Response final : public Body {
DEFINE_WRAPPERTYPEINFO();
public:
virtual ~Response() { }
// Constructors from Response.idl:
static Response* create(ExecutionContext*, ExceptionState&);
static Response* create(ExecutionContext*, Blob*, const Dictionary&, ExceptionState&);
static Response* create(ExecutionContext*, const String&, const Dictionary&, ExceptionState&);
static Response* create(ExecutionContext*, const DOMArrayBuffer*, const Dictionary&, ExceptionState&);
static Response* create(ExecutionContext*, const DOMArrayBufferView*, const Dictionary&, ExceptionState&);
static Response* create(ExecutionContext*, Blob*, const ResponseInit&, ExceptionState&);
static Response* create(ExecutionContext*, FetchResponseData*);
static Response* create(ExecutionContext*, const WebServiceWorkerResponse&);
......@@ -39,12 +42,14 @@ public:
const FetchResponseData* response() const { return m_response; }
// From Response.idl:
String type() const;
String url() const;
unsigned short status() const;
String statusText() const;
Headers* headers() const;
// From Response.idl:
Response* clone() const;
void populateWebServiceWorkerResponse(WebServiceWorkerResponse&);
......
......@@ -8,8 +8,9 @@ enum ResponseType { "basic", "cors", "default", "error", "opaque" };
[
// FIXME: Add ctors for FormData and URLSearchParams response bodies.
Constructor(),
Constructor(USVString body, optional Dictionary responseInitDict),
Constructor(Blob? body, optional Dictionary responseInitDict),
Constructor(Blob body, optional Dictionary responseInitDict),
Constructor(ArrayBuffer input, optional Dictionary requestInitDict),
Constructor(ArrayBufferView input, optional Dictionary requestInitDict),
ConstructorCallWith=ExecutionContext,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment