summaryrefslogtreecommitdiffstats
path: root/net/url_request
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-25 22:04:37 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-25 22:04:37 +0000
commit7e2639413fc87b91d1327a57303493d84823f070 (patch)
tree2c8f494e45fbd787ca2c1efbbbbee72826afd045 /net/url_request
parent7fe2c0b8630fabd9919dc61757392ea2aac9d72b (diff)
downloadchromium_src-7e2639413fc87b91d1327a57303493d84823f070.zip
chromium_src-7e2639413fc87b91d1327a57303493d84823f070.tar.gz
chromium_src-7e2639413fc87b91d1327a57303493d84823f070.tar.bz2
Append a trailing slash on file directory URLs. Thus a link to /directory will work just as well as a link to /directory/
Review URL: http://codereview.chromium.org/12620 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5999 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request')
-rw-r--r--net/url_request/url_request_file_dir_job.cc21
-rw-r--r--net/url_request/url_request_file_dir_job.h1
-rw-r--r--net/url_request/url_request_file_job.cc26
3 files changed, 27 insertions, 21 deletions
diff --git a/net/url_request/url_request_file_dir_job.cc b/net/url_request/url_request_file_dir_job.cc
index 4f94a42..df24eab 100644
--- a/net/url_request/url_request_file_dir_job.cc
+++ b/net/url_request/url_request_file_dir_job.cc
@@ -199,3 +199,24 @@ void URLRequestFileDirJob::CompleteRead() {
}
}
+bool URLRequestFileDirJob::IsRedirectResponse(
+ GURL* location, int* http_status_code) {
+ // If the URL did not have a trailing slash, treat the response as a redirect
+ // to the URL with a trailing slash appended.
+ std::string path = request_->url().path();
+ if (path.empty() || (path[path.size() - 1] != '/')) {
+ // This happens when we discovered the file is a directory, so needs a
+ // slash at the end of the path.
+ std::string new_path = path;
+ new_path.push_back('/');
+ GURL::Replacements replacements;
+ replacements.SetPathStr(new_path);
+
+ *location = request_->url().ReplaceComponents(replacements);
+ *http_status_code = 301; // simulate a permanent redirect
+ return true;
+ }
+
+ return false;
+}
+
diff --git a/net/url_request/url_request_file_dir_job.h b/net/url_request/url_request_file_dir_job.h
index 657a587..882f967 100644
--- a/net/url_request/url_request_file_dir_job.h
+++ b/net/url_request/url_request_file_dir_job.h
@@ -24,6 +24,7 @@ class URLRequestFileDirJob
virtual bool ReadRawData(char* buf, int buf_size, int *bytes_read);
virtual bool GetMimeType(std::string* mime_type);
virtual bool GetCharset(std::string* charset);
+ virtual bool IsRedirectResponse(GURL* location, int* http_status_code);
// DirectoryLister::DirectoryListerDelegate methods:
virtual void OnListFile(const file_util::FileEnumerator::FindInfo& data);
diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc
index 3c37468..d0841e5 100644
--- a/net/url_request/url_request_file_job.cc
+++ b/net/url_request/url_request_file_job.cc
@@ -72,12 +72,9 @@ class URLRequestFileJob::AsyncResolver :
URLRequestJob* URLRequestFileJob::Factory(
URLRequest* request, const std::string& scheme) {
FilePath file_path;
- if (net::FileURLToFilePath(request->url(), &file_path)) {
- if (file_util::DirectoryExists(file_path)) {
- // Only directories have trailing slashes.
+ if (net::FileURLToFilePath(request->url(), &file_path) &&
+ file_util::EnsureEndsWithSeparator(&file_path))
return new URLRequestFileDirJob(request, file_path);
- }
- }
// Use a regular file request job for all non-directories (including invalid
// file names).
@@ -167,13 +164,13 @@ void URLRequestFileJob::DidResolve(
if (!request_)
return;
- is_directory_ = file_info.is_directory;
+ DCHECK(!file_info.is_directory);
int rv = net::OK;
if (!exists) {
rv = net::ERR_FILE_NOT_FOUND;
- } else if (!is_directory_) {
- int flags = base::PLATFORM_FILE_OPEN |
+ } else {
+ int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_ASYNC;
rv = stream_.Open(file_path_.ToWStringHack(), flags);
@@ -200,19 +197,6 @@ void URLRequestFileJob::DidRead(int result) {
bool URLRequestFileJob::IsRedirectResponse(
GURL* location, int* http_status_code) {
- if (is_directory_) {
- // This happens when we discovered the file is a directory, so needs a
- // slash at the end of the path.
- std::string new_path = request_->url().path();
- new_path.push_back('/');
- GURL::Replacements replacements;
- replacements.SetPathStr(new_path);
-
- *location = request_->url().ReplaceComponents(replacements);
- *http_status_code = 301; // simulate a permanent redirect
- return true;
- }
-
#if defined(OS_WIN)
std::wstring extension =
file_util::GetFileExtensionFromPath(file_path_.value());