Commit 3646d015 authored by Robert Ogden's avatar Robert Ogden Committed by Commit Bot

Isolated Prerender Probing Ignores Surrounding Whitespace

Make sure surrounding whitespace, like a trailing newline, doesn't
fail the probe.

Bug: 1115731
Change-Id: I0acc753c7dd04dfa519b7a773870f5f2fdeb1d5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2432210Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811852}
parent 59926a3e
......@@ -745,7 +745,8 @@ class IsolatedPrerenderBrowserTest
std::unique_ptr<net::test_server::BasicHttpResponse> resp =
std::make_unique<net::test_server::BasicHttpResponse>();
resp->set_code(net::HTTP_OK);
resp->set_content("OK");
// Make sure whitespace is ok, especially trailing newline.
resp->set_content(" OK\n");
return resp;
}
......
......@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/no_destructor.h"
#include "base/strings/string_util.h"
#include "base/task/post_task.h"
#include "chrome/browser/availability/availability_prober.h"
#include "chrome/browser/prerender/isolated/isolated_prerender_params.h"
......@@ -189,8 +190,18 @@ class CanaryCheckDelegate : public AvailabilityProber::Delegate {
bool IsResponseSuccess(net::Error net_error,
const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) override {
return net_error == net::OK && head && head->headers &&
head->headers->response_code() == 200 && body && *body == "OK";
if (net_error != net::OK)
return false;
if (!head)
return false;
if (!head->headers)
return false;
if (head->headers->response_code() != 200)
return false;
if (!body)
return false;
// Strip any whitespace, especially trailing newlines.
return "OK" == base::TrimWhitespaceASCII(*body, base::TRIM_ALL);
}
};
......
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