Skip to content

Commit f1a205d

Browse files
committed
http: create header field names as internalized strings
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
1 parent 75aec8e commit f1a205d

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/node_http_parser.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ using v8::Isolate;
6565
using v8::Local;
6666
using v8::LocalVector;
6767
using v8::MaybeLocal;
68+
using v8::NewStringType;
6869
using v8::Number;
6970
using v8::Object;
7071
using v8::ObjectTemplate;
@@ -233,6 +234,17 @@ struct StringPtr {
233234
return String::Empty(env->isolate());
234235
}
235236

237+
Local<String> ToInternalizedString(Environment* env) const {
238+
if (size_ != 0) {
239+
return String::NewFromOneByte(env->isolate(),
240+
reinterpret_cast<const uint8_t*>(str_),
241+
NewStringType::kInternalized,
242+
size_)
243+
.ToLocalChecked();
244+
}
245+
return String::Empty(env->isolate());
246+
}
247+
236248
// Strip trailing OWS (SPC or HTAB) from string.
237249
Local<String> ToTrimmedString(Environment* env) {
238250
while (size_ > 0 && IsOWS(str_[size_ - 1])) {
@@ -940,7 +952,8 @@ class Parser : public AsyncWrap, public StreamListener {
940952
Local<Value> headers_v[kMaxHeaderFieldsCount * 2];
941953

942954
for (size_t i = 0; i < num_values_; ++i) {
943-
headers_v[i * 2] = fields_[i].ToString(env());
955+
// Field names repeat across requests, so internalize them.
956+
headers_v[i * 2] = fields_[i].ToInternalizedString(env());
944957
headers_v[i * 2 + 1] = values_[i].ToTrimmedString(env());
945958
}
946959

0 commit comments

Comments
 (0)