@@ -72,7 +72,7 @@ class HTTPHeaders {
7272 struct HTTPHeaderName {
7373 enum Type { CODE, STRING };
7474 union {
75- folly::StringPiece name_;
75+ std::string_view name_;
7676 HTTPHeaderCode code_;
7777 };
7878 Type type_;
@@ -82,13 +82,13 @@ class HTTPHeaders {
8282 /* implicit */ HTTPHeaderName(const char * name)
8383 : name_(name), type_(STRING) {
8484 }
85- /* implicit */ HTTPHeaderName(folly::StringPiece name)
85+ /* implicit */ HTTPHeaderName(std::string_view name)
8686 : name_(name), type_(STRING) {
8787 }
8888 };
8989
9090 using headers_initializer_list =
91- std::initializer_list<std::pair<HTTPHeaderName, folly::StringPiece >>;
91+ std::initializer_list<std::pair<HTTPHeaderName, std::string_view >>;
9292
9393 /*
9494 * separator used to concatenate multiple values of the same header
@@ -107,28 +107,20 @@ class HTTPHeaders {
107107 * Add the header 'name' with value 'value'; if other instances of this
108108 * header name exist, they will be retained.
109109 */
110- void add (folly::StringPiece name, std::string&& value);
111- void add (folly::StringPiece name, const std::string& value) {
110+ void add (std::string_view name, std::string&& value);
111+ void add (std::string_view name, std::string_view value) {
112112 add (name, std::string (value));
113113 }
114- void add (folly::StringPiece name, folly::StringPiece value) {
115- add (name, std::string (value));
116- }
117- // TODO(@damlaj): remove this fn & patch up all callsites
118- void add (folly::StringPiece name, const char * value) {
119- return add (name, std::string (value));
114+ FOLLY_ALWAYS_INLINE void add (std::string_view name, const char * value) {
115+ return add (name, std::string_view{value});
120116 }
121117
122118 void add (HTTPHeaderCode code, std::string&& value);
123- void add (HTTPHeaderCode code, const std::string& value) {
119+ void add (HTTPHeaderCode code, std::string_view value) {
124120 add (code, std::string (value));
125121 }
126- void add (HTTPHeaderCode code, folly::StringPiece value) {
127- add (code, std::string (value));
128- }
129- // TODO(@damlaj): remove this fn & patch up all callsites
130- void add (HTTPHeaderCode code, const char * value) {
131- return add (code, std::string (value));
122+ FOLLY_ALWAYS_INLINE void add (HTTPHeaderCode code, const char * value) {
123+ return add (code, std::string_view{value});
132124 }
133125
134126 void add (headers_initializer_list l);
@@ -137,12 +129,12 @@ class HTTPHeaders {
137129 * For the header 'name', set its value to the single header 'value',
138130 * removing any other instances of this header.
139131 */
140- void set (folly::StringPiece name, const std::string& value) {
132+ void set (std::string_view name, std::string_view value) {
141133 // this could be somewhat optimized but probably not an issue yet
142134 remove (name);
143135 add (name, value);
144136 }
145- void set (HTTPHeaderCode code, const std::string& value) {
137+ void set (HTTPHeaderCode code, std::string_view value) {
146138 remove (code);
147139 add (code, value);
148140 }
@@ -153,21 +145,18 @@ class HTTPHeaders {
153145 * argument it will remove x-y_z, x_y-z and x_y_z too and then set the given
154146 * header name, value.
155147 */
156- void setOneVersion (folly::StringPiece name,
148+ void setOneVersion (std::string_view name,
157149 HTTPHeaderCode code,
158- const std::string& value) {
150+ std::string_view value) {
159151 removeAllVersions (code, name);
160152 add (name, value);
161153 }
162154
163155 /* *
164156 * Do we have an instance of the given header?
165157 */
166- [[nodiscard]] bool exists (folly::StringPiece name) const ;
158+ [[nodiscard]] bool exists (std::string_view name) const ;
167159 [[nodiscard]] bool exists (HTTPHeaderCode code) const ;
168- bool rawExists (std::string& name) const {
169- return exists (name);
170- }
171160
172161 /* *
173162 * combine all the value for this header into a string
@@ -253,7 +242,7 @@ class HTTPHeaders {
253242 [[nodiscard]] SingleOrNullptrResult getSingleOrNullptr (
254243 HTTPHeaderCode code) const noexcept ;
255244 [[nodiscard]] SingleOrNullptrResult getSingleOrNullptr (
256- folly::StringPiece name) const noexcept ;
245+ std::string_view name) const noexcept ;
257246
258247 /* *
259248 * Returns the value of the header if it's found in the message and is the
@@ -262,7 +251,7 @@ class HTTPHeaders {
262251 */
263252 [[nodiscard]] const std::string& getSingleOrEmpty (HTTPHeaderCode code) const ;
264253 [[nodiscard]] const std::string& getSingleOrEmpty (
265- folly::StringPiece name) const ;
254+ std::string_view name) const ;
266255 [[nodiscard]] const std::string rawGet (const std::string& header) const {
267256 return getSingleOrEmpty (header);
268257 }
@@ -271,7 +260,7 @@ class HTTPHeaders {
271260 * Get the number of values corresponding to a given header name.
272261 */
273262 [[nodiscard]] size_t getNumberOfValues (HTTPHeaderCode code) const ;
274- [[nodiscard]] size_t getNumberOfValues (folly::StringPiece name) const ;
263+ [[nodiscard]] size_t getNumberOfValues (std::string_view name) const ;
275264
276265 /* *
277266 * Process the ordered list of values for the given header name:
@@ -286,7 +275,7 @@ class HTTPHeaders {
286275 * true), and false otherwise.
287276 */
288277 using ForEachValueOfHeaderFnT = std::function<bool (const std::string&)>;
289- bool forEachValueOfHeader (folly::StringPiece name,
278+ bool forEachValueOfHeader (std::string_view name,
290279 const ForEachValueOfHeaderFnT& func) const ;
291280 bool forEachValueOfHeader (HTTPHeaderCode code,
292281 const ForEachValueOfHeaderFnT& func) const ;
@@ -295,7 +284,7 @@ class HTTPHeaders {
295284 * Remove all instances of the given header, returning true if anything was
296285 * removed and false if this header didn't exist in our set.
297286 */
298- bool remove (folly::StringPiece name);
287+ bool remove (std::string_view name);
299288 bool remove (HTTPHeaderCode code);
300289 void rawRemove (const std::string& name) {
301290 remove (name);
@@ -305,7 +294,7 @@ class HTTPHeaders {
305294 * Remove all possible versions of header eg. if x-y-z is the
306295 * argument it will remove x-y_z, x_y-z and x_y_z too.
307296 */
308- bool removeAllVersions (HTTPHeaderCode code, folly::StringPiece name);
297+ bool removeAllVersions (HTTPHeaderCode code, std::string_view name);
309298
310299 /* *
311300 * Remove all headers.
@@ -365,7 +354,7 @@ class HTTPHeaders {
365354 * group. No-op if the header doesn't exist. Returns true if header(s) were
366355 * moved.
367356 */
368- bool transferHeaderIfPresent (folly::StringPiece name, HTTPHeaders& dest);
357+ bool transferHeaderIfPresent (std::string_view name, HTTPHeaders& dest);
369358
370359 // deletes the strings in headerNames_ that we own
371360 void disposeOfHeaderNames ();
0 commit comments