Skip to content

Commit 6da4d74

Browse files
committed
Wrap getParameter(name)
1 parent eb0787f commit 6da4d74

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/HttpRequestWrapper.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,25 @@ struct HttpRequestWrapper {
5858
}
5959
}
6060

61-
/* Takes int, returns string (must be in bounds) */
61+
/* Takes int or string, returns string (must be in bounds) */
6262
template <int QUIC>
6363
static void req_getParameter(const FunctionCallbackInfo<Value> &args) {
6464
Isolate *isolate = args.GetIsolate();
6565
auto *req = getHttpRequest<QUIC>(args);
6666
if (req) {
67-
int index = args[0]->Uint32Value(isolate->GetCurrentContext()).ToChecked();
68-
std::string_view parameter = req->getParameter(index);
67+
68+
/* Either an integer index or string name */
69+
std::string_view parameter;
70+
if (args[0]->IsNumber()) {
71+
int index = args[0]->Uint32Value(isolate->GetCurrentContext()).ToChecked();
72+
parameter = req->getParameter(index);
73+
} else {
74+
NativeString data(args.GetIsolate(), args[0]);
75+
if (data.isInvalid(args)) {
76+
return;
77+
}
78+
parameter = req->getParameter(data.getString());
79+
}
6980

7081
args.GetReturnValue().Set(String::NewFromUtf8(isolate, parameter.data(), NewStringType::kNormal, parameter.length()).ToLocalChecked());
7182
}

0 commit comments

Comments
 (0)