Skip to content

Commit fff2fbc

Browse files
committed
http: only internalize short header field names
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
1 parent f1a205d commit fff2fbc

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/node_http_common.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class Environment;
1616
#define DEFAULT_MAX_HEADER_LIST_PAIRS 128u
1717
#define DEFAULT_MAX_HEADER_LENGTH 8192
1818

19+
constexpr size_t kMaxInternalizedHeaderNameLength = 64;
20+
1921
#define HTTP_SPECIAL_HEADERS(V) \
2022
V(STATUS, ":status") \
2123
V(METHOD, ":method") \
@@ -432,7 +434,7 @@ class NgRcBufPointer : public MemoryRetainer {
432434
return v8::String::Empty(env->isolate());
433435
}
434436

435-
if (ptr.IsInternalizable() && len < 64) {
437+
if (ptr.IsInternalizable() && len < kMaxInternalizedHeaderNameLength) {
436438
v8::MaybeLocal<v8::String> ret = GetInternalizedString(env, ptr);
437439
ptr.reset();
438440
return ret;

src/node_http_parser.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "llhttp.h"
2929
#include "memory_tracker-inl.h"
3030
#include "node_external_reference.h"
31+
#include "node_http_common.h"
3132
#include "stream_base-inl.h"
3233
#include "v8.h"
3334

@@ -235,14 +236,15 @@ struct StringPtr {
235236
}
236237

237238
Local<String> ToInternalizedString(Environment* env) const {
238-
if (size_ != 0) {
239+
// Only internalize short names to avoid pressuring the string table.
240+
if (size_ != 0 && size_ < kMaxInternalizedHeaderNameLength) {
239241
return String::NewFromOneByte(env->isolate(),
240242
reinterpret_cast<const uint8_t*>(str_),
241243
NewStringType::kInternalized,
242244
size_)
243245
.ToLocalChecked();
244246
}
245-
return String::Empty(env->isolate());
247+
return ToString(env);
246248
}
247249

248250
// Strip trailing OWS (SPC or HTAB) from string.

0 commit comments

Comments
 (0)