File: headers.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (123 lines) | stat: -rw-r--r-- 4,314 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// 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_