summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-13 07:23:32 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-13 07:23:32 +0000
commita53fa7f6730aa13061007e988c94f549026d72b9 (patch)
tree805fbcc19812f281eaae81f76c5e10d36386b773 /net
parent22bb4c8769a0860ce098ce19ac71a253dcd06437 (diff)
downloadchromium_src-a53fa7f6730aa13061007e988c94f549026d72b9.zip
chromium_src-a53fa7f6730aa13061007e988c94f549026d72b9.tar.gz
chromium_src-a53fa7f6730aa13061007e988c94f549026d72b9.tar.bz2
Another tweak to about:net-internals: do a redirect after processing the query arguments.
BUG=None TEST=None Review URL: http://codereview.chromium.org/546028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36111 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/url_request/url_request_view_net_internals_job.cc70
-rw-r--r--net/url_request/url_request_view_net_internals_job.h9
2 files changed, 46 insertions, 33 deletions
diff --git a/net/url_request/url_request_view_net_internals_job.cc b/net/url_request/url_request_view_net_internals_job.cc
index 7ee7d7f..58aa3d7 100644
--- a/net/url_request/url_request_view_net_internals_job.cc
+++ b/net/url_request/url_request_view_net_internals_job.cc
@@ -479,23 +479,6 @@ class AllSubSections : public SubSection {
}
};
-// Returns true if |path| is a subpath for "view-cache".
-// If it is, then |key| is assigned the subpath.
-bool GetViewCacheKeyFromPath(const std::string path,
- std::string* key) {
- if (!StartsWithASCII(path, kViewHttpCacheSubPath, true))
- return false;
-
- if (path.size() > strlen(kViewHttpCacheSubPath) &&
- path[strlen(kViewHttpCacheSubPath)] != '/')
- return false;
-
- if (path.size() > strlen(kViewHttpCacheSubPath) + 1)
- *key = path.substr(strlen(kViewHttpCacheSubPath) + 1);
-
- return true;
-}
-
bool HandleCommand(const std::string& command, URLRequestContext* context) {
if (StartsWithASCII(command, "full-logging-", true)) {
bool enable_full_logging = (command == "full-logging-enable");
@@ -578,28 +561,27 @@ bool URLRequestViewNetInternalsJob::GetData(std::string* mime_type,
charset->assign("UTF-8");
URLRequestContext* context = request_->context();
- std::string details = url_format_->GetDetails(request_->url());
data->clear();
// Use a different handler for "view-cache/*" subpaths.
std::string cache_key;
- if (GetViewCacheKeyFromPath(details, &cache_key)) {
+ if (GetViewCacheKeyForRequest(&cache_key)) {
GURL url = url_format_->MakeURL(kViewHttpCacheSubPath + std::string("/"));
ViewCacheHelper::GetEntryInfoHTML(cache_key, context, url.spec(), data);
return true;
}
- std::string query;
-
- // Split out the query parameters.
- std::string::size_type query_start = details.find('?');
- if (query_start != std::string::npos) {
- if (query_start + 1 < details.size())
- query = details.substr(query_start + 1);
- details = details.substr(0, query_start);
+ // Handle any query arguments as a command request, then redirect back to
+ // the same URL stripped of query parameters. The redirect happens as part
+ // of IsRedirectResponse().
+ if (request_->url().has_query()) {
+ ProcessQueryStringCommands(context, request_->url().query());
+ return true;
}
+ std::string details = url_format_->GetDetails(request_->url());
+
data->append("<!DOCTYPE HTML>"
"<html><head><title>Network internals</title>"
"<style>"
@@ -629,11 +611,6 @@ bool URLRequestViewNetInternalsJob::GetData(std::string* mime_type,
"developers/design-documents/view-net-internals'>"
"Help: how do I use this?</a></p>");
- // TODO(eroman): do a redirect after processing the commands, to clear the
- // URL of the command string (otherwise if you refresh the page you
- // re-execute the command, which can be confusing when that command was to
- // clear all the data!).
- ProcessQueryStringCommands(context, query);
DrawControlsHeader(context, data);
SubSection* all = Singleton<AllSubSections>::get();
@@ -655,3 +632,32 @@ bool URLRequestViewNetInternalsJob::GetData(std::string* mime_type,
return true;
}
+
+bool URLRequestViewNetInternalsJob::IsRedirectResponse(GURL* location,
+ int* http_status_code) {
+ if (request_->url().has_query() && !GetViewCacheKeyForRequest(NULL)) {
+ // Strip the query parameters.
+ GURL::Replacements replacements;
+ replacements.ClearQuery();
+ *location = request_->url().ReplaceComponents(replacements);
+ *http_status_code = 307;
+ return true;
+ }
+ return false;
+}
+
+bool URLRequestViewNetInternalsJob::GetViewCacheKeyForRequest(
+ std::string* key) const {
+ std::string path = url_format_->GetDetails(request_->url());
+ if (!StartsWithASCII(path, kViewHttpCacheSubPath, true))
+ return false;
+
+ if (path.size() > strlen(kViewHttpCacheSubPath) &&
+ path[strlen(kViewHttpCacheSubPath)] != '/')
+ return false;
+
+ if (key && path.size() > strlen(kViewHttpCacheSubPath) + 1)
+ *key = path.substr(strlen(kViewHttpCacheSubPath) + 1);
+
+ return true;
+}
diff --git a/net/url_request/url_request_view_net_internals_job.h b/net/url_request/url_request_view_net_internals_job.h
index 9f23f96..3d1eff3 100644
--- a/net/url_request/url_request_view_net_internals_job.h
+++ b/net/url_request/url_request_view_net_internals_job.h
@@ -21,14 +21,21 @@ class URLRequestViewNetInternalsJob : public URLRequestSimpleJob {
URLFormat* url_format)
: URLRequestSimpleJob(request), url_format_(url_format) {}
- // override from URLRequestSimpleJob
+ // URLRequestSimpleJob methods:
virtual bool GetData(std::string* mime_type,
std::string* charset,
std::string* data) const;
+ // Overridden methods from URLRequestJob:
+ virtual bool IsRedirectResponse(GURL* location, int* http_status_code);
+
private:
~URLRequestViewNetInternalsJob() {}
+ // Returns true if the current request is for a "view-cache" URL.
+ // If it is, then |key| is assigned the particular cache URL of the request.
+ bool GetViewCacheKeyForRequest(std::string* key) const;
+
URLFormat* url_format_;
};