#include "content/browser/devtools/protocol/fetch_handler.h"
#include <memory>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/devtools/devtools_agent_host_impl.h"
#include "content/browser/devtools/devtools_io_context.h"
#include "content/browser/devtools/devtools_stream_pipe.h"
#include "content/browser/devtools/devtools_url_loader_interceptor.h"
#include "content/browser/devtools/protocol/network_handler.h"
#include "content/public/browser/browser_thread.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h"
#include "net/http/http_util.h"
namespace content {
namespace protocol {
std::vector<FetchHandler*> FetchHandler::ForAgentHost(
DevToolsAgentHostImpl* host) { … }
FetchHandler::FetchHandler(
DevToolsIOContext* io_context,
UpdateLoaderFactoriesCallback update_loader_factories_callback)
: … { … }
FetchHandler::~FetchHandler() = default;
void FetchHandler::Wire(UberDispatcher* dispatcher) { … }
DevToolsURLLoaderInterceptor::InterceptionStage RequestStageToInterceptorStage(
const Fetch::RequestStage& stage) { … }
Response ToInterceptionPatterns(
Maybe<Array<Fetch::RequestPattern>>& maybe_patterns,
std::vector<DevToolsURLLoaderInterceptor::Pattern>* result) { … }
bool FetchHandler::MaybeCreateProxyForInterception(
int process_id,
StoragePartition* storage_partition,
const base::UnguessableToken& frame_token,
bool is_navigation,
bool is_download,
network::mojom::URLLoaderFactoryOverride* intercepting_factory) { … }
void FetchHandler::Enable(Maybe<Array<Fetch::RequestPattern>> patterns,
Maybe<bool> handleAuth,
std::unique_ptr<EnableCallback> callback) { … }
Response FetchHandler::Disable() { … }
namespace {
ContinueInterceptedRequestCallback;
template <typename Callback, typename Base, typename... Args>
class CallbackWrapper : public Base { … };
template <typename Callback>
std::unique_ptr<CallbackWrapper<Callback, ContinueInterceptedRequestCallback>>
WrapCallback(std::unique_ptr<Callback> cb) { … }
template <typename Callback>
bool ValidateHeaders(Fetch::HeaderEntry* entry, Callback* callback) { … }
}
void FetchHandler::FailRequest(const String& requestId,
const String& errorReason,
std::unique_ptr<FailRequestCallback> callback) { … }
namespace {
std::string GetReasonPhrase(int responseCode) { … }
}
void FetchHandler::FulfillRequest(
const String& requestId,
int responseCode,
Maybe<Array<Fetch::HeaderEntry>> responseHeaders,
Maybe<Binary> binaryResponseHeaders,
Maybe<Binary> body,
Maybe<String> responsePhrase,
std::unique_ptr<FulfillRequestCallback> callback) { … }
void FetchHandler::ContinueRequest(
const String& requestId,
Maybe<String> url,
Maybe<String> method,
Maybe<protocol::Binary> postData,
Maybe<Array<Fetch::HeaderEntry>> headers,
Maybe<bool> interceptResponse,
std::unique_ptr<ContinueRequestCallback> callback) { … }
void FetchHandler::ContinueWithAuth(
const String& requestId,
std::unique_ptr<protocol::Fetch::AuthChallengeResponse>
authChallengeResponse,
std::unique_ptr<ContinueWithAuthCallback> callback) { … }
void FetchHandler::ContinueResponse(
const String& requestId,
Maybe<int> responseCode,
Maybe<String> responsePhrase,
Maybe<Array<Fetch::HeaderEntry>> responseHeaders,
Maybe<Binary> binaryResponseHeaders,
std::unique_ptr<ContinueResponseCallback> callback) { … }
void FetchHandler::GetResponseBody(
const String& requestId,
std::unique_ptr<GetResponseBodyCallback> callback) { … }
void FetchHandler::TakeResponseBodyAsStream(
const String& requestId,
std::unique_ptr<TakeResponseBodyAsStreamCallback> callback) { … }
void FetchHandler::OnResponseBodyPipeTaken(
std::unique_ptr<TakeResponseBodyAsStreamCallback> callback,
Response response,
mojo::ScopedDataPipeConsumerHandle pipe,
const std::string& mime_type) { … }
namespace {
std::unique_ptr<Array<Fetch::HeaderEntry>> ToHeaderEntryArray(
scoped_refptr<net::HttpResponseHeaders> headers) { … }
}
void FetchHandler::RequestIntercepted(
std::unique_ptr<InterceptedRequestInfo> info) { … }
}
}