Make QuicMemoryCacheBackend::InitializedBackend correctly support Windows paths. This method attempts to turn file system paths into URL host/path. It does so by looking for '/' characters explicitly but that's not the path separator on windows. It's '\\'. This change replaces all '\\' characters in the path with '/' before parsing.
Technically it's possible that on non-windows platforms some filename might actually contain a '\\' character, but since this is a toy tool I think we don't need to worry about that case.
gfe-relnote: Not used in the GFE
PiperOrigin-RevId: 285334250
Change-Id: I68925dd2272e52df023f3f98ce0878dc6021943e
diff --git a/quic/tools/quic_memory_cache_backend.cc b/quic/tools/quic_memory_cache_backend.cc
index a769259..ddf94fe 100644
--- a/quic/tools/quic_memory_cache_backend.cc
+++ b/quic/tools/quic_memory_cache_backend.cc
@@ -104,14 +104,15 @@
void QuicMemoryCacheBackend::ResourceFile::SetHostPathFromBase(
quiche::QuicheStringPiece base) {
+ DCHECK(base[0] != '/') << base;
size_t path_start = base.find_first_of('/');
- DCHECK_LT(0UL, path_start);
- host_ = base.substr(0, path_start);
+ DCHECK(path_start != quiche::QuicheStringPiece::npos) << base;
+ host_ = std::string(base.substr(0, path_start));
size_t query_start = base.find_first_of(',');
if (query_start > 0) {
- path_ = base.substr(path_start, query_start - 1);
+ path_ = std::string(base.substr(path_start, query_start - 1));
} else {
- path_ = base.substr(path_start);
+ path_ = std::string(base.substr(path_start));
}
}
@@ -127,9 +128,7 @@
void QuicMemoryCacheBackend::ResourceFile::HandleXOriginalUrl() {
quiche::QuicheStringPiece url(x_original_url_);
- // Remove the protocol so we can add it below.
- url = RemoveScheme(url);
- SetHostPathFromBase(url);
+ SetHostPathFromBase(RemoveScheme(url));
}
const QuicBackendResponse* QuicMemoryCacheBackend::GetResponse(
@@ -256,10 +255,16 @@
std::unique_ptr<ResourceFile> resource_file(new ResourceFile(filename));
// Tease apart filename into host and path.
- quiche::QuicheStringPiece base(resource_file->file_name());
- base.remove_prefix(cache_directory.length());
+ std::string base(resource_file->file_name());
+ // Transform windows path separators to URL path separators.
+ for (size_t i = 0; i < base.length(); ++i) {
+ if (base[i] == '\\') {
+ base[i] = '/';
+ }
+ }
+ base.erase(0, cache_directory.length());
if (base[0] == '/') {
- base.remove_prefix(1);
+ base.erase(0, 1);
}
resource_file->SetHostPathFromBase(base);
diff --git a/quic/tools/quic_memory_cache_backend.h b/quic/tools/quic_memory_cache_backend.h
index 54151da..38d445c 100644
--- a/quic/tools/quic_memory_cache_backend.h
+++ b/quic/tools/quic_memory_cache_backend.h
@@ -66,8 +66,8 @@
spdy::SpdyHeaderBlock spdy_headers_;
quiche::QuicheStringPiece x_original_url_;
std::vector<quiche::QuicheStringPiece> push_urls_;
- quiche::QuicheStringPiece host_;
- quiche::QuicheStringPiece path_;
+ std::string host_;
+ std::string path_;
};
QuicMemoryCacheBackend();