Chromium 中js Fetch API接口c++代码实现(一)

news2024/10/8 19:47:02

Fetch API主要暴露了三个接口一个方法。


  • 三个接口
    • Request(资源请求)
    • Response(请求的响应)
    • Headers(Request/Response头部信息)
  • 一个方法
    • fetch()(获取资源调用的方法
    • 更多介绍参考 Fetch API - Web API | MDN (mozilla.org)

一、 来看一段前端代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test fetch</title>
<script>
function Test() {
 fetch("http://192.168.8.1/chfs/shared/test/format.1728106021784.json")
  .then((response) => response.json())
  .then((data) => console.log(data));

}
</script>
</head>
<body>
 
<button onclick="Test()">Test fetch</button>
 
</body>
</html>

二、看c++代码对fetch response具体实现

1、services\network\public\mojom\fetch_api.mojom

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module network.mojom;

// Corresponds to Fetch request's "mode" and "use-CORS-preflight flag":
// https://fetch.spec.whatwg.org/#concept-request-mode
//
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum RequestMode {
  kSameOrigin = 0,
  kNoCors = 1,
  kCors = 2,
  kCorsWithForcedPreflight = 3,
  kNavigate = 4,
  // Add a new type here, then update "FetchRequestMode" in enums.xml.
};

// Corresponds to Fetch request's "destination":
// https://fetch.spec.whatwg.org/#concept-request-destination
//
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum RequestDestination {
  kEmpty = 0,
  kAudio = 1,
  kAudioWorklet = 2,
  // kDocument is for a main resource request in a main frame, or a Portal.
  kDocument = 3,
  kEmbed = 4,
  kFont = 5,
  kFrame = 6,
  kIframe = 7,
  kImage = 8,
  kManifest = 9,
  kObject = 10,
  kPaintWorklet = 11,
  kReport = 12,
  kScript = 13,
  kServiceWorker = 14,
  kSharedWorker = 15,
  kStyle = 16,
  kTrack = 17,
  kVideo = 18,
  // kWebBundle represents a request for a WebBundle. A <script> element whose
  // type is "webbundle" uses this destination.
  //
  // e.g. <script type=webbundle> { "source": "foo.wbn", ... } </script>
  //
  // Fetch specifiction does not define this destination yet.
  // Tracking issue: https://github.com/whatwg/fetch/issues/1120
  kWebBundle = 19,
  kWorker = 20,
  kXslt = 21,
  // kFencedframe represents a main resource request in a fenced frame. A
  // <fencedframe> element uses this destination.
  //
  // e.g. <fencedframe src="example.com"></fencedframe>
  //
  // Fenced Frame is not standardized yet. See
  // https://github.com/shivanigithub/fenced-frame for the explainer and
  // crbug.com/1123606 for the implementation.
  kFencedframe = 22,
  // Requests from the federated credential management API,
  // https://fedidcg.github.io/FedCM/
  kWebIdentity = 23,
  // Requests for compression dictionary
  kDictionary = 24,
  // Requests for speculation rules.
  // https://wicg.github.io/nav-speculation/speculation-rules.html
  kSpeculationRules = 25,
};

// Corresponds to Fetch request's "redirect mode":
// https://fetch.spec.whatwg.org/#concept-request-redirect-mode
enum RedirectMode {
  kFollow,
  kError,
  kManual,
};

// Corresponds to Fetch request's "credentials mode":
// https://fetch.spec.whatwg.org/#concept-request-credentials-mode
enum CredentialsMode {
  // TODO(https://crbug.com/775438): Due to a bug, this does not properly
  // correspond to Fetch's "credentials mode", in that client certificates will
  // be sent is available, or the handshake will be aborted in order to allow
  // selecting a client cert. The correct behavior is to omit all client certs
  // and continue the handshake without sending one if requested.
  kOmit,

  kSameOrigin,
  kInclude,

  // TODO(https://crbug.com/775438): This works around kOmit not doing the
  // spec-defined behavior. This is a temporary workaround that explicitly
  // indicates the caller wants the spec-defined behavior. It's named as such
  // because this should be only temporary, until kOmit is fixed.
  kOmitBug_775438_Workaround
};

// Corresponds to response types from the Fetch spec:
// https://fetch.spec.whatwg.org/#concept-response-type
//
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum FetchResponseType {
  kBasic = 0,
  kCors = 1,
  kDefault = 2,
  kError = 3,
  kOpaque = 4,
  kOpaqueRedirect = 5,
  // Add a new type here, then update "FetchResponseType" in enums.xml.
};

// Indicates the source of a response.
// This represents the source of the outmost response of a request.
// This is used only for histograms and isn't web-exposed.
enum FetchResponseSource {
  // The source is unspecified: e.g. "new Response('hi')" or a response from
  // a service worker.
  kUnspecified,
  // The response came from network: e.g. "fetch(req)".
  kNetwork,
  // The response came from HttpCache: e.g. "fetch(req)" and there is an entry
  // in HttpCache.
  kHttpCache,
  // The response came from CacheStorage: e.g. "cache.match(req)" in a fetch
  // event handler.
  kCacheStorage,
};

2、在third_party\blink\renderer\core\fetch\global_fetch.h 定义了Fetch函数具体实现

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_GLOBAL_FETCH_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_GLOBAL_FETCH_H_

#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_typedefs.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/fetch/request.h"

namespace blink {

class ExceptionState;
class LocalDOMWindow;
class NavigatorBase;
class RequestInit;
class DeferredRequestInit;
class ScriptState;
class WorkerGlobalScope;
class FetchLaterResult;

class CORE_EXPORT GlobalFetch {
  STATIC_ONLY(GlobalFetch);

 public:
  class CORE_EXPORT ScopedFetcher : public GarbageCollectedMixin {
   public:
    virtual ~ScopedFetcher();

    virtual ScriptPromise Fetch(ScriptState*,
                                const V8RequestInfo*,
                                const RequestInit*,
                                ExceptionState&) = 0;

    virtual FetchLaterResult* FetchLater(ScriptState*,
                                         const V8RequestInfo*,
                                         const DeferredRequestInit*,
                                         ExceptionState&);

    // Returns the number of fetch() method calls in the associated execution
    // context.  This is used for metrics.
    virtual uint32_t FetchCount() const = 0;

    static ScopedFetcher* From(LocalDOMWindow&);
    static ScopedFetcher* From(WorkerGlobalScope&);
    static ScopedFetcher* From(NavigatorBase& navigator);

    void Trace(Visitor*) const override;
  };

  static ScriptPromise fetch(ScriptState* script_state,
                             LocalDOMWindow& window,
                             const V8RequestInfo* input,
                             const RequestInit* init,
                             ExceptionState& exception_state);
  static ScriptPromise fetch(ScriptState* script_state,
                             WorkerGlobalScope& worker,
                             const V8RequestInfo* input,
                             const RequestInit* init,
                             ExceptionState& exception_state);

  static FetchLaterResult* fetchLater(ScriptState* script_state,
                                      LocalDOMWindow& window,
                                      const V8RequestInfo* input,
                                      const DeferredRequestInit* init,
                                      ExceptionState& exception_state);
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_GLOBAL_FETCH_H_

3、Fetch 管理类 third_party\blink\renderer\core\fetch\fetch_manager.h

4、前端接口 Request(资源请求) third_party\blink\renderer\core\fetch\headers.idl

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// https://fetch.spec.whatwg.org/#typedefdef-headersinit

typedef (sequence<sequence<ByteString>> or record<ByteString, ByteString>) HeadersInit;

// https://fetch.spec.whatwg.org/#headers-class

[
    Exposed=(Window,Worker)
] interface Headers {
    [CallWith=ScriptState, RaisesException] constructor(optional HeadersInit init);
    [CallWith=ScriptState, RaisesException] void append(ByteString name, ByteString value);
    [CallWith=ScriptState, ImplementedAs=remove, RaisesException] void delete(ByteString key);
    [RaisesException] ByteString? get(ByteString key);
    sequence<ByteString> getSetCookie();
    [RaisesException] boolean has(ByteString key);
    [CallWith=ScriptState, RaisesException] void set(ByteString key, ByteString value);
    iterable<ByteString, ByteString>;
};

对应实现c++类:

third_party\blink\renderer\core\fetch\headers.h

third_party\blink\renderer\core\fetch\headers.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_HEADERS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_HEADERS_H_

#include "third_party/blink/renderer/bindings/core/v8/iterable.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_sync_iterator_headers.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_typedefs.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/fetch/fetch_header_list.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_set.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"

namespace blink {

class ExceptionState;
class ScriptState;

// http://fetch.spec.whatwg.org/#headers-class
class CORE_EXPORT Headers final : public ScriptWrappable,
                                  public PairSyncIterable<Headers> {
  DEFINE_WRAPPERTYPEINFO();

 public:
  enum Guard {
    kImmutableGuard,
    kRequestGuard,
    kRequestNoCorsGuard,
    kResponseGuard,
    kNoneGuard
  };

  static Headers* Create(ScriptState* script_state,
                         ExceptionState& exception_state);
  static Headers* Create(ScriptState* script_state,
                         const V8HeadersInit* init,
                         ExceptionState& exception_state);

  // Shares the FetchHeaderList. Called when creating a Request or Response.
  static Headers* Create(FetchHeaderList*);

  Headers();
  // Shares the FetchHeaderList. Called when creating a Request or Response.
  explicit Headers(FetchHeaderList*);

  Headers* Clone() const;

  // Headers.idl implementation.
  void append(ScriptState* script_state,
              const String& name,
              const String& value,
              ExceptionState&);
  void remove(ScriptState* script_state, const String& key, ExceptionState&);
  String get(const String& key, ExceptionState&);
  Vector<String> getSetCookie();
  bool has(const String& key, ExceptionState&);
  void set(ScriptState* script_state,
           const String& key,
           const String& value,
           ExceptionState&);

  void SetGuard(Guard guard) { guard_ = guard; }
  Guard GetGuard() const { return guard_; }

  // These methods should only be called when size() would return 0.
  void FillWith(ScriptState* script_state, const Headers*, ExceptionState&);
  void FillWith(ScriptState* script_state,
                const V8HeadersInit* init,
                ExceptionState& exception_state);

  // https://fetch.spec.whatwg.org/#concept-headers-remove-privileged-no-cors-request-headers
  void RemovePrivilegedNoCorsRequestHeaders();

  FetchHeaderList* HeaderList() const { return header_list_.Get(); }
  void Trace(Visitor*) const override;

 private:
  class HeadersIterationSource final
      : public PairSyncIterable<Headers>::IterationSource {
   public:
    explicit HeadersIterationSource(Headers* headers);
    ~HeadersIterationSource() override;

    bool FetchNextItem(ScriptState* script_state,
                       String& key,
                       String& value,
                       ExceptionState& exception) override;

    void Trace(Visitor*) const override;

    void ResetHeaderList();

   private:
    // https://webidl.spec.whatwg.org/#dfn-value-pairs-to-iterate-over
    Vector<std::pair<String, String>> headers_list_;
    // https://webidl.spec.whatwg.org/#default-iterator-object-index
    wtf_size_t current_ = 0;
    Member<Headers> headers_;
  };

  // These methods should only be called when size() would return 0.
  void FillWith(ScriptState* script_state,
                const Vector<Vector<String>>&,
                ExceptionState&);
  void FillWith(ScriptState* script_state,
                const Vector<std::pair<String, String>>&,
                ExceptionState&);

  Member<FetchHeaderList> header_list_;
  Guard guard_;

  IterationSource* CreateIterationSource(ScriptState*,
                                         ExceptionState&) override;

  HeapHashSet<WeakMember<HeadersIterationSource>> iterators_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_HEADERS_H_

5、Response(请求的响应) third_party\blink\renderer\core\fetch\response.idl

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// https://fetch.spec.whatwg.org/#response-class

enum ResponseType { "basic", "cors", "default", "error", "opaque", "opaqueredirect" };

[
    Exposed=(Window,Worker)
] interface Response {
    // TODO(yhirano): We use "any" for body because the IDL processor doesn't
    // recognize ReadableStream implemented with V8 extras. Fix it.
    [CallWith=ScriptState, RaisesException] constructor(optional any body, optional ResponseInit init = {});
    [CallWith=ScriptState, NewObject] static Response error();
    [CallWith=ScriptState, NewObject, RaisesException] static Response redirect(USVString url, optional unsigned short status = 302);
    [CallWith=ScriptState, NewObject, RaisesException, ImplementedAs=staticJson] static Response json(any data, optional ResponseInit init = {});
    readonly attribute ResponseType type;
    readonly attribute USVString url;
    readonly attribute boolean redirected;
    readonly attribute unsigned short status;
    readonly attribute boolean ok;
    readonly attribute ByteString statusText;
    [SameObject] readonly attribute Headers headers;

    [RaisesException, CallWith=ScriptState, NewObject] Response clone();

    [Affects=Everything, MeasureAs=FetchBodyStream] readonly attribute ReadableStream? body;
};

Response includes Body;

对应response接口c++实现类:

third_party\blink\renderer\core\fetch\response.h

third_party\blink\renderer\core\fetch\response.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_RESPONSE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_RESPONSE_H_

#include "services/network/public/mojom/fetch_api.mojom-blink.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_response.mojom-blink-forward.h"
#include "third_party/blink/renderer/bindings/core/v8/dictionary.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/fetch/body.h"
#include "third_party/blink/renderer/core/fetch/body_stream_buffer.h"
#include "third_party/blink/renderer/core/fetch/fetch_response_data.h"
#include "third_party/blink/renderer/core/fetch/headers.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/blob/blob_data.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

class ExceptionState;
class ResponseInit;
class ScriptState;

class CORE_EXPORT Response final : public ScriptWrappable, public Body {
  DEFINE_WRAPPERTYPEINFO();

 public:
  // These "create" function which takes a ScriptState* must be called with
  // entering an appropriate V8 context.
  // From Response.idl:
  static Response* Create(ScriptState*, ExceptionState&);
  static Response* Create(ScriptState*,
                          ScriptValue body,
                          const ResponseInit*,
                          ExceptionState&);

  static Response* Create(ScriptState*,
                          BodyStreamBuffer*,
                          const String& content_type,
                          const ResponseInit*,
                          ExceptionState&);
  static Response* Create(ExecutionContext*, FetchResponseData*);
  static Response* Create(ScriptState*, mojom::blink::FetchAPIResponse&);

  static Response* CreateClone(const Response&);

  static Response* error(ScriptState*);
  static Response* redirect(ScriptState*,
                            const String& url,
                            uint16_t status,
                            ExceptionState&);
  static Response* staticJson(ScriptState*,
                              ScriptValue data,
                              const ResponseInit*,
                              ExceptionState&);

  static FetchResponseData* CreateUnfilteredFetchResponseDataWithoutBody(
      ScriptState*,
      mojom::blink::FetchAPIResponse&);

  static FetchResponseData* FilterResponseData(
      network::mojom::FetchResponseType response_type,
      FetchResponseData* response,
      WTF::Vector<WTF::String>& headers);

  explicit Response(ExecutionContext*);
  Response(ExecutionContext*, FetchResponseData*);
  Response(ExecutionContext*, FetchResponseData*, Headers*);
  Response(const Response&) = delete;
  Response& operator=(const Response&) = delete;

  const FetchResponseData* GetResponse() const { return response_.Get(); }

  // From Response.idl:
  String type() const;
  String url() const;
  bool redirected() const;
  uint16_t status() const;
  bool ok() const;
  String statusText() const;
  Headers* headers() const;

  // From Response.idl:
  // This function must be called with entering an appropriate V8 context.
  Response* clone(ScriptState*, ExceptionState&);

  // Does not contain the blob response body or any side data blob.
  // |request_url| is the current request URL that resulted in the response. It
  // is needed to process some response headers (e.g. CSP).
  // TODO(lfg, kinuko): The FetchResponseData::url_list_ should include the
  // request URL per step 9 in Main Fetch
  // https://fetch.spec.whatwg.org/#main-fetch. Just fixing it might break the
  // logic in ResourceMultiBufferDataProvider, please see
  // https://chromium-review.googlesource.com/c/1366464 for more details.
  mojom::blink::FetchAPIResponsePtr PopulateFetchAPIResponse(
      const KURL& request_url);

  bool HasBody() const;
  BodyStreamBuffer* BodyBuffer() override { return response_->Buffer(); }
  // Returns the BodyStreamBuffer of |m_response|. This method doesn't check
  // the internal response of |m_response| even if |m_response| has it.
  const BodyStreamBuffer* BodyBuffer() const override {
    return response_->Buffer();
  }
  // Returns the BodyStreamBuffer of the internal response of |m_response| if
  // any. Otherwise, returns one of |m_response|.
  BodyStreamBuffer* InternalBodyBuffer() { return response_->InternalBuffer(); }
  const BodyStreamBuffer* InternalBodyBuffer() const {
    return response_->InternalBuffer();
  }

  bool IsBodyUsed() const override;

  String ContentType() const override;
  String MimeType() const override;
  String InternalMIMEType() const;

  const Vector<KURL>& InternalURLList() const;

  FetchHeaderList* InternalHeaderList() const;

  void Trace(Visitor*) const override;

 private:
  const Member<FetchResponseData> response_;
  const Member<Headers> headers_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_RESPONSE_H_

  1)、 Response  body对应实现类:third_party\blink\renderer\core\fetch\body.idl

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// https://fetch.spec.whatwg.org/#body

[
    ActiveScriptWrappable
] interface mixin Body {
    readonly attribute boolean bodyUsed;
    [CallWith=ScriptState, NewObject, RaisesException] Promise<ArrayBuffer> arrayBuffer();
    [CallWith=ScriptState, NewObject, RaisesException] Promise<Blob> blob();
    [CallWith=ScriptState, NewObject, RaisesException] Promise<FormData> formData();
    [CallWith=ScriptState, NewObject, RaisesException] Promise<any> json();
    [CallWith=ScriptState, NewObject, RaisesException] Promise<USVString> text();

    // body attribute is defined in sub-interfaces, because the IDL processor
    // cannot deal with attribute inheritance with runtime enabled flag.
    // [RuntimeEnabled=ExperimentalStream] readonly attribute ReadableByteStream body;
};

third_party\blink\renderer\core\fetch\body.h  

third_party\blink\renderer\core\fetch\body.cc 

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_BODY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_BODY_H_

#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace blink {

class BodyStreamBuffer;
class ExceptionState;
class ExecutionContext;
class ReadableStream;
class ScriptPromiseResolver;
class ScriptState;

// This class represents Body mix-in defined in the fetch spec
// https://fetch.spec.whatwg.org/#body-mixin.
//
// Note: This class has body stream and its predicate whereas in the current
// spec only Response has it and Request has a byte stream defined in the
// Encoding spec. The spec should be fixed shortly to be aligned with this
// implementation.
class CORE_EXPORT Body : public ExecutionContextClient {
 public:
  explicit Body(ExecutionContext*);
  Body(const Body&) = delete;
  Body& operator=(const Body&) = delete;

  ScriptPromise arrayBuffer(ScriptState*, ExceptionState&);
  ScriptPromise blob(ScriptState*, ExceptionState&);
  ScriptPromise formData(ScriptState*, ExceptionState&);
  ScriptPromise json(ScriptState*, ExceptionState&);
  ScriptPromise text(ScriptState*, ExceptionState&);
  ReadableStream* body();
  virtual BodyStreamBuffer* BodyBuffer() = 0;
  virtual const BodyStreamBuffer* BodyBuffer() const = 0;

  // This should only be called from the generated bindings. All other code
  // should use IsBodyUsed() instead.
  bool bodyUsed() const { return IsBodyUsed(); }

  // True if the body has been read from.
  virtual bool IsBodyUsed() const;

  // True if the body is locked.
  bool IsBodyLocked() const;

 private:
  // TODO(e_hakkinen): Fix |MimeType()| to always contain parameters and
  // remove |ContentType()|.
  virtual String ContentType() const = 0;
  virtual String MimeType() const = 0;

  // Body consumption algorithms will reject with a TypeError in a number of
  // error conditions. This method wraps those up into one call which throws
  // an exception if consumption cannot proceed. The caller must check
  // |exception_state| on return.
  void RejectInvalidConsumption(ExceptionState& exception_state) const;

  // The parts of LoadAndConvertBody() that do not depend on the template
  // parameters are split into this method to reduce binary size. Returns a
  // freshly-created ScriptPromiseResolver* on success, or nullptr on error. On
  // error, LoadAndConvertBody() must not continue.
  ScriptPromiseResolver* PrepareToLoadBody(ScriptState*, ExceptionState&);

  // Common implementation for body-reading accessors. To maximise performance
  // at the cost of code size, this is templated on the types of the lambdas
  // that are passed in.
  template <class Consumer,
            typename CreateLoaderFunction,
            typename OnNoBodyFunction>
  ScriptPromise LoadAndConvertBody(ScriptState*,
                                   CreateLoaderFunction,
                                   OnNoBodyFunction,
                                   ExceptionState&);
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_BODY_H_

6、Headers(Request/Response头部信息) third_party\blink\renderer\core\fetch\headers.idl

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// https://fetch.spec.whatwg.org/#typedefdef-headersinit

typedef (sequence<sequence<ByteString>> or record<ByteString, ByteString>) HeadersInit;

// https://fetch.spec.whatwg.org/#headers-class

[
    Exposed=(Window,Worker)
] interface Headers {
    [CallWith=ScriptState, RaisesException] constructor(optional HeadersInit init);
    [CallWith=ScriptState, RaisesException] void append(ByteString name, ByteString value);
    [CallWith=ScriptState, ImplementedAs=remove, RaisesException] void delete(ByteString key);
    [RaisesException] ByteString? get(ByteString key);
    sequence<ByteString> getSetCookie();
    [RaisesException] boolean has(ByteString key);
    [CallWith=ScriptState, RaisesException] void set(ByteString key, ByteString value);
    iterable<ByteString, ByteString>;
};

至此定义实现已经介绍完毕,在下一篇看下调用堆栈:

Chromium 中JavaScript Fetch API接口c++代码实现(二)-CSDN博客

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2197097.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

ssm图书管理系统的设计与实现

系统包含&#xff1a;源码论文 所用技术&#xff1a;SpringBootVueSSMMybatisMysql 免费提供给大家参考或者学习&#xff0c;获取源码请私聊我 需要定制请私聊 目 录 摘 要 I Abstract II 第1章 绪论 1 1.1 课题研究背景 1 1.2课题研究现状 1 1.3课题实现目的和意义 …

【C++】模拟实现hash_table(哈希表)

&#x1f984;个人主页:修修修也 &#x1f38f;所属专栏:实战项目集 ⚙️操作环境:Visual Studio 2022 目录 一.了解项目功能 二.逐步实现项目功能模块及其逻辑详解 &#x1f4cc;实现HashNode类模板 &#x1f38f;构造HashNode类成员变量 &#x1f38f;实现HashNode类构造函数…

高效研究:Zotero的7个插件让你事半功倍

还在为海量文献管理头疼吗?还在为找不到合适的插件犯愁吗?别急,今天我就要带你解锁Zotero的终极武器 - 那些让你爱不释手的必备插件! 作为一个从小白到文献管理达人的过来人,我可以负责任地说:没有这些插件,你的Zotero只能发挥一半功力!安装了这些插件,你的效率绝对能飙升! …

字典树(单词查找树、Trie树)

题目 代码 #include <bits/stdc.h> using namespace std; const int N 1e510; int f[N][26], idx, cnt[N]; void insert(char str[]) {int p 0;for(int i 0; str[i]; i){int u str[i] - a;if(!f[p][u]) f[p][u] idx;p f[p][u];}cnt[p]; } int query(char str[]) …

相亲交友系统的商业模式探讨

在撰写关于相亲交友系统的商业模式探讨时&#xff0c;附带示例代码可能不太合适&#xff0c;因为软文通常是面向非技术读者&#xff0c;讲述商业模式、用户体验等方面的内容。不过&#xff0c;为了满足您的需求&#xff0c;我可以尝试结合一些简单的伪代码&#xff08;模拟代码…

CSS 3D转换

在 CSS 中&#xff0c;除了可以对页面中的元素进行 2D 转换外&#xff0c;您也可以对象元素进行 3D转换&#xff08;将页面看作是一个三维空间来对页面中的元素进行移动、旋转、缩放和倾斜等操作&#xff09;。与 2D 转换相同&#xff0c;3D 转换同样不会影响周围的元素&#x…

Cursor编辑器:10秒生成完美Git提交信息!

Cursor编辑器&#xff1a;10秒生成完美Git提交信息&#xff01; 亲爱的开发者们&#xff0c;是否还在为编写规范的Git提交信息而头疼&#xff1f;今天&#xff0c;就让我们一起揭开Cursor编辑器的神秘面纱&#xff0c;探索如何一键生成专业的Git Commit Message&#xff0c;让…

Android 电源管理各个版本的变动和限制

由于Android设备的电池容量有限&#xff0c;而用户在使用过程中会进行各种高耗电操作&#xff0c;如网络连接、屏幕亮度调节、后台程序运行等&#xff0c;因此需要通过各种省电措施来优化电池使用‌&#xff0c;延长电池续航时间&#xff0c;提高用户体验&#xff0c;并减少因电…

数据结构-八大排序之堆排序

堆排序 1.1 基础知识 原理&#xff1a; 1. 利用完全二叉树构建大顶堆 2. 堆顶元素和堆底元素进行交换&#xff0c;除堆底元素之外其余元素继续构建大顶堆 3. 重复2&#xff0c;直到所有元素都不参与构建 整个数组排序完成 完全二叉树&#xff1a; 数据从上到下&#x…

八大排序--05堆排序

假设数组 arr[] {5,7,4,2,0,3,1,6},请通过插入排序的方式&#xff0c;实现从小到大排列&#xff1a; 方法&#xff1a;①利用完全二叉树构建大顶堆&#xff1b; ②对顶元素和堆底元素进行交换&#xff0c;除堆底元素之外其余元素继续构造大顶堆&#xff1b; ③重复步骤②&…

2k1000LA iso 镜像的制作

问题: 已经有了buildroot ,内核也调试好了,但是没有loongnix 镜像。 首先是网上下载镜像,看看能不能用 首先是现在 网上的 iso 镜像进行烧写测试。 安装 7z 解压软件 进行U盘的烧写。 进行系统安装测试: <

视频剪辑软件推荐电脑版:这5款剪辑软件不容错过!

在视频剪辑领域&#xff0c;选择合适的软件至关重要。不同的软件各有千秋&#xff0c;有的简单易用&#xff0c;适合新手快速上手&#xff1b;有的功能强大&#xff0c;适合专业团队进行深度编辑。以下是一些电脑版视频剪辑软件的推荐&#xff0c;涵盖了从新手到专业级别的不同…

【RAG】HiQA:一种用于多文档问答的层次化上下文增强RAG

前言 文档领域的RAG&#xff0c;之前的工作如ChatPDF等很多的RAG框架&#xff0c;文档数量一旦增加&#xff0c;将导致响应准确性下降&#xff0c;如下图&#xff1b;现有RAG方法在处理具有相似内容&#xff08;在面对大量难以区分的文档时&#xff09;和结构的文档时表现不佳…

人才画像系统是什么?有哪些功能和作用?

人才画像系统是一种先进的人力资源管理工具&#xff0c;它运用大数据和人工智能技术对员工的多方面特征进行深度分析。系统通过汇聚个人的教育背景、工作经验、技能掌握、性格特质及行为数据等信息&#xff0c;结合数据挖掘和机器学习算法&#xff0c;构建出每位员工的数字化“…

openEuler 22.03 (LTS-SP3)上安装mysql8单机版

一、目标 在openEuler 22.03 (LTS-SP3) 上安装 mysql 8.0.23 单机版 二、安装 1、下载二进制包 MySQL :: Download MySQL Community Server (Archived Versions) 下载页面 下载链接 https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.23-linux-glibc2.12-x86…

新生培训 day1 C语言基础 顺序 分支 循环 数组 字符串 函数

比赛地址 b牛客竞赛_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ C语言数据类型 字符 整型数 int 2e9 long long 9e18 浮点数 代码示例 /** Author: Dduo * Date: 2024-10-8* Description: 新生培训day1 */ #include <stdio.h>int main() {// 定义变量in…

【2024.10.8练习】宝石组合

题目描述 题目分析 由于是求最值&#xff0c;原本考虑贪心&#xff0c;但由于算式过于复杂&#xff0c;首先考虑对算式化简。 进行质因数分解&#xff1a; 因此: 不妨设对于每个&#xff0c;&#xff0c;则上式可化简为&#xff1a; 即 用Vene图也可以求出同样结果。 可是以…

DepthB2R靶机打靶记录

一、靶机介绍 下载地址&#xff1a;https://download.vulnhub.com/depth/DepthB2R.ova 二、信息收集 根据靶机主页显示&#xff0c;确认靶机ip为192.168.242.132 端口扫描 nmap -p- -A 192.168.242.132 发现只开放了8080端口 用dirsearch扫个目录 apt-get update apt-get …

胤娲科技:机械臂「叛逃」记——自由游走,再悄然合体

夜深人静&#xff0c;你正沉浸在梦乡的前奏&#xff0c;突然意识到房间的灯还亮着。此刻的你&#xff0c;是否幻想过有一只无形的手&#xff0c;轻盈地飘过&#xff0c;帮你熄灭那盏碍眼的灯&#xff1f; 又或者&#xff0c;你正窝在沙发上&#xff0c;享受电视剧的紧张刺激&am…

RKMEDIA画面质量调节-QP调节

QP是在视频采集编码过程中的量化参数&#xff0c;其值与画面质量成反比&#xff0c;即QP值越大画面质量越小&#xff0c;其具体调整方法如下&#xff1a; typedef struct rkVENC_RC_PARAM_S {RK_U32 u32ThrdI[RC_TEXTURE_THR_SIZE]; // [0, 255]RK_U32 u32ThrdP[RC_TEXTURE_TH…