Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1889)

Unified Diff: Source/modules/fetch/Response.cpp

Issue 1098473003: Implement redirect() API for Fetch Response (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/fetch/Response.cpp
diff --git a/Source/modules/fetch/Response.cpp b/Source/modules/fetch/Response.cpp
index fcc11891b0f07569487c2dfce1f2f150855b53ea..0863925b33142597ae7fa5f517bdbcfa4bc16b8a 100644
--- a/Source/modules/fetch/Response.cpp
+++ b/Source/modules/fetch/Response.cpp
@@ -243,6 +243,28 @@ Response* Response::error(ExecutionContext* context)
return r;
}
+Response* Response::redirect(ExecutionContext* context, const String& url, unsigned short status, ExceptionState& exceptionState)
+{
+ KURL parsedURL = context->completeURL(url);
+ if (!parsedURL.isValid()) {
+ exceptionState.throwTypeError("Failed to parse URL from " + url);
+ return nullptr;
+ }
+
+ if (status != 301 && status != 302 && status != 303 && status != 307 && status != 308) {
+ exceptionState.throwRangeError("Invalid status code");
+ return nullptr;
+ }
+
+ Response* r = new Response(context);
+ r->suspendIfNeeded();
+ r->m_headers->setGuard(Headers::ImmutableGuard);
+ r->m_response->setStatus(status);
+ r->m_response->headerList()->set("Location", parsedURL);
+
+ return r;
+}
+
String Response::type() const
{
// "The type attribute's getter must return response's type."

Powered by Google App Engine
This is Rietveld 408576698