@@ -16,6 +16,20 @@ struct HttpRequestWrapper {
1616 return req;
1717 }
1818
19+ /* Takes function of string, string. Returns this (doesn't really but should) */
20+ static void req_forEach (const FunctionCallbackInfo<Value> &args) {
21+ auto *req = getHttpRequest (args);
22+ if (req) {
23+ Local<Function> cb = Local<Function>::Cast (args[0 ]);
24+
25+ for (auto p : *req) {
26+ Local<Value> argv[] = {String::NewFromUtf8 (isolate, p.first .data (), String::kNormalString , p.first .length ()),
27+ String::NewFromUtf8 (isolate, p.second .data (), String::kNormalString , p.second .length ())};
28+ cb->Call (isolate->GetCurrentContext ()->Global (), 2 , argv);
29+ }
30+ }
31+ }
32+
1933 /* Takes int, returns string (must be in bounds) */
2034 static void req_getParameter (const FunctionCallbackInfo<Value> &args) {
2135 auto *req = getHttpRequest (args);
@@ -83,6 +97,7 @@ struct HttpRequestWrapper {
8397 reqTemplateLocal->PrototypeTemplate ()->Set (String::NewFromUtf8 (isolate, " getUrl" ), FunctionTemplate::New (isolate, req_getUrl));
8498 reqTemplateLocal->PrototypeTemplate ()->Set (String::NewFromUtf8 (isolate, " getMethod" ), FunctionTemplate::New (isolate, req_getMethod));
8599 reqTemplateLocal->PrototypeTemplate ()->Set (String::NewFromUtf8 (isolate, " getQuery" ), FunctionTemplate::New (isolate, req_getQuery));
100+ reqTemplateLocal->PrototypeTemplate ()->Set (String::NewFromUtf8 (isolate, " forEach" ), FunctionTemplate::New (isolate, req_forEach));
86101
87102 /* Create the template */
88103 Local<Object> reqObjectLocal = reqTemplateLocal->GetFunction ()->NewInstance (isolate->GetCurrentContext ()).ToLocalChecked ();
0 commit comments