summaryrefslogtreecommitdiff
path: root/chromium/net/url_request/url_request_job_factory.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/net/url_request/url_request_job_factory.cc')
-rw-r--r--chromium/net/url_request/url_request_job_factory.cc32
1 files changed, 23 insertions, 9 deletions
diff --git a/chromium/net/url_request/url_request_job_factory.cc b/chromium/net/url_request/url_request_job_factory.cc
index 8ff76c530df..079187d608d 100644
--- a/chromium/net/url_request/url_request_job_factory.cc
+++ b/chromium/net/url_request/url_request_job_factory.cc
@@ -20,19 +20,30 @@ namespace {
URLRequestInterceptor* g_interceptor_for_testing = nullptr;
-// TODO(mmenke): Once FTP support is removed, look into removing this class, and
-// URLRequestJobFactory::ProtocolHandlers completely. The only other subclass is
-// iOS-only.
+// TODO(mmenke): Look into removing this class and
+// URLRequestJobFactory::ProtocolHandlers completely. The only other subclass
+// is iOS-only.
class HttpProtocolHandler : public URLRequestJobFactory::ProtocolHandler {
public:
- HttpProtocolHandler() = default;
+ // URLRequest::is_for_websockets() must match `is_for_websockets`, or requests
+ // will be failed. This is so that attempts to fetch WebSockets requests
+ // fails, and attempts to use HTTP URLs for WebSockets also fail.
+ explicit HttpProtocolHandler(bool is_for_websockets)
+ : is_for_websockets_(is_for_websockets) {}
+
HttpProtocolHandler(const HttpProtocolHandler&) = delete;
HttpProtocolHandler& operator=(const HttpProtocolHandler&) = delete;
~HttpProtocolHandler() override = default;
std::unique_ptr<URLRequestJob> CreateJob(URLRequest* request) const override {
+ if (request->is_for_websockets() != is_for_websockets_) {
+ return std::make_unique<URLRequestErrorJob>(request,
+ ERR_UNKNOWN_URL_SCHEME);
+ }
return URLRequestHttpJob::Create(request);
}
+
+ const bool is_for_websockets_;
};
} // namespace
@@ -45,12 +56,15 @@ bool URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(
}
URLRequestJobFactory::URLRequestJobFactory() {
- SetProtocolHandler(url::kHttpScheme, std::make_unique<HttpProtocolHandler>());
- SetProtocolHandler(url::kHttpsScheme,
- std::make_unique<HttpProtocolHandler>());
+ SetProtocolHandler(url::kHttpScheme, std::make_unique<HttpProtocolHandler>(
+ /*is_for_websockets=*/false));
+ SetProtocolHandler(url::kHttpsScheme, std::make_unique<HttpProtocolHandler>(
+ /*is_for_websockets=*/false));
#if BUILDFLAG(ENABLE_WEBSOCKETS)
- SetProtocolHandler(url::kWsScheme, std::make_unique<HttpProtocolHandler>());
- SetProtocolHandler(url::kWssScheme, std::make_unique<HttpProtocolHandler>());
+ SetProtocolHandler(url::kWsScheme, std::make_unique<HttpProtocolHandler>(
+ /*is_for_websockets=*/true));
+ SetProtocolHandler(url::kWssScheme, std::make_unique<HttpProtocolHandler>(
+ /*is_for_websockets=*/true));
#endif // BUILDFLAG(ENABLE_WEBSOCKETS)
}