network: Move HasFetchStreamingUploadBody to url_loader_util
Moves the static helper function `HasFetchStreamingUploadBody` from `URLLoader` class to the `url_loader_util` namespace. This function determines if a ResourceRequest represents a fetch upload with a streaming body. As a static helper that doesn't depend on `URLLoader` state and is also used by `CorsURLLoader`, it's better placed in a shared utility location like `url_loader_util`. This refactoring improves code organization by grouping related URL loading utilities together and makes the function more easily accessible where needed. Existing call sites in URLLoader and CorsURLLoader are updated accordingly. A descriptive comment explaining the function's logic has also been added to the header file (`url_loader_util.h`). Bug: 408106280 Change-Id: Iff637d6352b87fd5025e10986ea8966eda98865b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6437943 Reviewed-by: Kenichi Ishibashi <bashi@chromium.org> Commit-Queue: Tsuyoshi Horo <horo@chromium.org> Cr-Commit-Position: refs/heads/main@{#1444555}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
331c55a13c
commit
fa1d584c1b
services/network
@ -766,7 +766,7 @@ void CorsURLLoader::OnReceiveRedirect(const net::RedirectInfo& redirect_info,
|
||||
// See 4.4. HTTP-redirect fetch
|
||||
// (https://fetch.spec.whatwg.org/#http-redirect-fetch), step 11.
|
||||
if (redirect_info.status_code != net::HTTP_SEE_OTHER &&
|
||||
network::URLLoader::HasFetchStreamingUploadBody(&request_)) {
|
||||
url_loader_util::HasFetchStreamingUploadBody(request_)) {
|
||||
HandleComplete(URLLoaderCompletionStatus(net::ERR_INVALID_ARGUMENT));
|
||||
return;
|
||||
}
|
||||
|
@ -443,7 +443,8 @@ URLLoader::URLLoader(
|
||||
ad_auction_event_record_request_helper_(
|
||||
request.attribution_reporting_eligibility,
|
||||
url_loader_network_observer_.get()),
|
||||
has_fetch_streaming_upload_body_(HasFetchStreamingUploadBody(&request)),
|
||||
has_fetch_streaming_upload_body_(
|
||||
url_loader_util::HasFetchStreamingUploadBody(request)),
|
||||
accept_ch_frame_observer_(std::move(accept_ch_frame_observer)),
|
||||
allow_cookies_from_browser_(
|
||||
request.trusted_params &&
|
||||
@ -1417,19 +1418,6 @@ void URLLoader::ContinueOnReceiveRedirect(
|
||||
std::move(response));
|
||||
}
|
||||
|
||||
// static
|
||||
bool URLLoader::HasFetchStreamingUploadBody(const ResourceRequest* request) {
|
||||
const ResourceRequestBody* request_body = request->request_body.get();
|
||||
if (!request_body)
|
||||
return false;
|
||||
const std::vector<DataElement>* elements = request_body->elements();
|
||||
if (elements->size() != 1u)
|
||||
return false;
|
||||
const auto& element = elements->front();
|
||||
return element.type() == mojom::DataElementDataView::Tag::kChunkedDataPipe &&
|
||||
element.As<network::DataElementChunkedDataPipe>().read_only_once();
|
||||
}
|
||||
|
||||
void URLLoader::OnAuthRequired(net::URLRequest* url_request,
|
||||
const net::AuthChallengeInfo& auth_info) {
|
||||
if (has_fetch_streaming_upload_body_) {
|
||||
|
@ -300,8 +300,6 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) URLLoader
|
||||
|
||||
static const void* const kUserDataKey;
|
||||
|
||||
static bool HasFetchStreamingUploadBody(const ResourceRequest*);
|
||||
|
||||
// Returns an optional reference to a constant permissions policy that belongs
|
||||
// to the request. `this` must outlive the caller of this method.
|
||||
base::optional_ref<const network::PermissionsPolicy> GetPermissionsPolicy()
|
||||
|
@ -280,6 +280,22 @@ class FileElementReader : public net::UploadFileElementReader {
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// Returns if `request` is fetch upload request with a streaming body.
|
||||
bool HasFetchStreamingUploadBody(const ResourceRequest& request) {
|
||||
const ResourceRequestBody* request_body = request.request_body.get();
|
||||
if (!request_body) {
|
||||
return false;
|
||||
}
|
||||
const std::vector<DataElement>* elements = request_body->elements();
|
||||
if (elements->size() != 1u) {
|
||||
return false;
|
||||
}
|
||||
const auto& element = elements->front();
|
||||
return element.type() == mojom::DataElementDataView::Tag::kChunkedDataPipe &&
|
||||
element.As<network::DataElementChunkedDataPipe>().read_only_once();
|
||||
}
|
||||
|
||||
std::unique_ptr<net::UploadDataStream> CreateUploadDataStream(
|
||||
ResourceRequestBody* body,
|
||||
std::vector<base::File>& opened_files,
|
||||
|
@ -44,6 +44,11 @@ class ResourceRequestBody;
|
||||
|
||||
namespace url_loader_util {
|
||||
|
||||
// Returns true if `request` represents a fetch upload request with a streaming
|
||||
// body. This is determined by checking if the request body contains exactly
|
||||
// one element, which is a read-only-once chunked data pipe.
|
||||
bool HasFetchStreamingUploadBody(const ResourceRequest&);
|
||||
|
||||
// Creates a net::UploadDataStream from the passed `body` and `opened_files`.
|
||||
// `file_task_runner` will be used for reading file elements in the `body`.
|
||||
std::unique_ptr<net::UploadDataStream> CreateUploadDataStream(
|
||||
|
Reference in New Issue
Block a user