-
Notifications
You must be signed in to change notification settings - Fork 23
/
http3server.cc
595 lines (524 loc) · 23.2 KB
/
http3server.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
// Copyright (c) 2022 Marten Richter or other contributers (see commit). All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// portions taken from libquiche, original copyright, see LICENSE.chromium
// Copyright (c) The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "absl/cleanup/cleanup.h"
#include "src/http3server.h"
#include "src/http3dispatcher.h"
#include "src/http3wtsessionvisitor.h"
#include "quiche/quic/core/quic_default_packet_writer.h"
#include "quiche/quic/core/quic_default_connection_helper.h"
#include "quiche/quic/core/quic_default_clock.h"
#include "quiche/quic/tools/quic_simple_crypto_server_stream_helper.h"
#include "quiche/quic/core/crypto/proof_source_x509.h"
#include "quiche/common/platform/api/quiche_reference_counted.h"
using namespace Napi;
namespace quic
{
const size_t kNumSessionsToCreatePerSocketEvent = 16;
Http3Server::Http3Server(Http3ServerJS *js, std::unique_ptr<ProofSource> proof_source,
const char *secret, QuicConfig config)
: config_(config),
http3_server_backend_(),
packet_reader_(new QuicPacketReader()),
packets_dropped_(0),
version_manager_({ParsedQuicVersion::RFCv1()}),
crypto_config_(secret,
QuicRandom::GetInstance(),
std::move(proof_source),
KeyExchangeSource::Default()),
expected_server_connection_id_length_(kQuicDefaultConnectionIdLength),
js_(js),
connection_id_generator_(expected_server_connection_id_length_)
{
// may be put somewhereelse
dispatcher_.reset(CreateQuicDispatcher());
dispatcher_->InitializeWithWriter(new SocketJSWriter(getJS()));
// may be put somewhereelse
const uint32_t kInitialSessionFlowControlWindow = 1 * 1024 * 1024; // 1 MB
const uint32_t kInitialStreamFlowControlWindow = 64 * 1024; // 64 KB
if (config_.GetInitialStreamFlowControlWindowToSend() ==
kDefaultFlowControlSendWindow)
{
config_.SetInitialStreamFlowControlWindowToSend(
kInitialStreamFlowControlWindow);
}
if (config_.GetInitialSessionFlowControlWindowToSend() ==
kDefaultFlowControlSendWindow)
{
config_.SetInitialSessionFlowControlWindowToSend(
kInitialSessionFlowControlWindow);
}
}
Http3Server::~Http3Server()
{
// printf("server destruct %x\n", this);
}
// TODO make call from JS
void Http3Server::Destroy()
{
// if (!silent_close_) {
// Before we shut down the epoll server, give all active sessions a chance
// to notify clients that they're closing.
dispatcher_->Shutdown();
//}
}
QuicDispatcher *Http3Server::CreateQuicDispatcher()
{
http3_server_backend_.setServer(this);
return new Http3Dispatcher(
&config_, &crypto_config_, &version_manager_,
std::unique_ptr<QuicDefaultConnectionHelper>(new QuicDefaultConnectionHelper()),
std::unique_ptr<QuicCryptoServerStreamBase::Helper>(
new QuicSimpleCryptoServerStreamHelper()),
std::unique_ptr<QuicAlarmFactory>(new NapiAlarmFactory(QuicDefaultClock::Get(), getJS())),
&http3_server_backend_, expected_server_connection_id_length_, connection_id_generator_);
}
Http3ServerJS::Http3ServerJS(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Http3ServerJS>(info)
{
std::string secret;
std::vector<std::string> cert;
std::vector<std::string> privkey;
QuicConfig sconfig;
if (!info[0].IsUndefined())
{
Napi::Object lobj = info[0].ToObject();
if (!lobj.IsEmpty())
{
if (lobj.Has("secret") && !(lobj).Get("secret").IsEmpty())
{
Napi::Value secretValue = (lobj).Get("secret");
secret = secretValue.ToString().Utf8Value();
}
else
{
Napi::Error::New(Env(), "No secret set for Http3Server").ThrowAsJavaScriptException();
return;
}
if (lobj.Has("cert") && !(lobj).Get("cert").IsEmpty())
{
Napi::Value certValue = (lobj).Get("cert");
if (!certValue.IsArray()) {
cert.push_back(certValue.ToString().Utf8Value());
} else {
Napi::Array certArray = certValue.As<Napi::Array>();
if (certArray.Length() < 1) Napi::Error::New(Env(), "No cert in array for Http3Server").ThrowAsJavaScriptException();
for (uint32_t i = 0; i < certArray.Length(); i++) {
Napi::Value curval = certArray.Get(i);
cert.push_back(curval.ToString().Utf8Value());
}
}
}
else
{
Napi::Error::New(Env(), "No cert set for Http3Server").ThrowAsJavaScriptException();
return;
}
if (lobj.Has("privKey") && !(lobj).Get("privKey").IsEmpty())
{
Napi::Value keyValue = (lobj).Get("privKey");
if (!keyValue.IsArray()) {
privkey.push_back(keyValue.ToString().Utf8Value());
} else {
Napi::Array keyArray = keyValue.As<Napi::Array>();
if (keyArray.Length() < 1) Napi::Error::New(Env(), "No key in array for Http3Server").ThrowAsJavaScriptException();
for (uint32_t i = 0; i < keyArray.Length(); i++) {
Napi::Value curval = keyArray.Get(i);
privkey.push_back(curval.ToString().Utf8Value());
}
}
}
else
{
Napi::Error::New(Env(), "No privKey set for Http3Server").ThrowAsJavaScriptException();
return;
}
if (privkey.size() != cert.size()) Napi::Error::New(Env(), "Key and cert array length for Http3Server do not match").ThrowAsJavaScriptException();
if (lobj.Has("maxConnections") && !(lobj).Get("maxConnections").IsEmpty())
{
Napi::Value maxconnValue = (lobj).Get("maxConnections");
int maxconn = maxconnValue.As<Napi::Number>().Int32Value();
sconfig.SetMaxBidirectionalStreamsToSend(maxconn);
sconfig.SetMaxUnidirectionalStreamsToSend(maxconn);
}
if (lobj.Has("initialBidirectionalStreams") && !(lobj).Get("initialBidirectionalStreams").IsEmpty())
{
Napi::Value initialBidirectionalStreamsValue = (lobj).Get("initialBidirectionalStreams");
int initialBidirectionalStreams = initialBidirectionalStreamsValue.As<Napi::Number>().Int32Value();
sconfig.SetMaxBidirectionalStreamsToSend(initialBidirectionalStreams);
}
if (lobj.Has("initialUnidirectionalStreams") && !(lobj).Get("initialUnidirectionalStreams").IsEmpty())
{
Napi::Value initialUnidirectionalStreamsValue = (lobj).Get("initialUnidirectionalStreams");
int initialUnidirectionalStreams = initialUnidirectionalStreamsValue.As<Napi::Number>().Int32Value();
sconfig.SetMaxUnidirectionalStreamsToSend(initialUnidirectionalStreams);
}
if (lobj.Has("initialStreamFlowControlWindow") && !(lobj).Get("initialStreamFlowControlWindow").IsEmpty())
{
Napi::Value initialStreamFlowControlWindowValue = (lobj).Get("initialStreamFlowControlWindow");
int initialStreamFlowControlWindow = initialStreamFlowControlWindowValue.As<Napi::Number>().Int32Value();
sconfig.SetInitialStreamFlowControlWindowToSend(initialStreamFlowControlWindow);
}
if (lobj.Has("initialSessionFlowControlWindow") && !(lobj).Get("initialSessionFlowControlWindow").IsEmpty())
{
Napi::Value initialSessionFlowControlWindowValue = (lobj).Get("initialSessionFlowControlWindow");
int initialSessionFlowControlWindow = initialSessionFlowControlWindowValue.As<Napi::Number>().Int32Value();
sconfig.SetInitialSessionFlowControlWindowToSend(initialSessionFlowControlWindow);
}
if (lobj.Has("streamFlowControlWindowSizeLimit") && !(lobj).Get("streamFlowControlWindowSizeLimit").IsEmpty())
{
Napi::Value streamFlowControlWindowSizeLimitValue = (lobj).Get("streamFlowControlWindowSizeLimit");
int streamFlowControlWindowSizeLimitWindow = streamFlowControlWindowSizeLimitValue.As<Napi::Number>().Int32Value();
sconfig.SetInitialMaxStreamDataBytesOutgoingBidirectionalToSend(streamFlowControlWindowSizeLimitWindow);
sconfig.SetInitialMaxStreamDataBytesIncomingBidirectionalToSend(streamFlowControlWindowSizeLimitWindow);
sconfig.SetInitialMaxStreamDataBytesUnidirectionalToSend(streamFlowControlWindowSizeLimitWindow);
}
}
// Callback *callback, int port, std::unique_ptr<ProofSource> proof_source, const char *secret
std::stringstream certstream(cert[0], std::ios_base::in);
quiche::QuicheReferenceCountedPointer<ProofSource::Chain> chain(new ProofSource::Chain(CertificateView::LoadPemFromStream(&certstream)));
std::stringstream privkeystream(privkey[0], std::ios_base::in);
auto certprivkey = CertificatePrivateKey::LoadPemFromStream(&privkeystream);
if (certprivkey == nullptr)
{
Napi::Error::New(Env(), "LoadPemFromStream privKey failed for Http3Server").ThrowAsJavaScriptException();
return;
}
std::unique_ptr<ProofSourceX509> proofsource = ProofSourceX509::Create(chain, std::move(*certprivkey));
if (proofsource == nullptr)
{
Napi::Error::New(Env(), "LoadPemFromStream cert failed for Http3Server").ThrowAsJavaScriptException();
return;
}
// add additional certs to proof source
for (size_t i = 1; i < cert.size(); i++)
{
std::stringstream addcertstream(cert[0], std::ios_base::in);
quiche::QuicheReferenceCountedPointer<ProofSource::Chain> addchain(new ProofSource::Chain(CertificateView::LoadPemFromStream(&addcertstream)));
std::stringstream addprivkeystream(privkey[0], std::ios_base::in);
auto addcertprivkey = CertificatePrivateKey::LoadPemFromStream(&privkeystream);
if (addcertprivkey == nullptr)
{
Napi::Error::New(Env(), "LoadPemFromStream addprivKey failed for Http3Server").ThrowAsJavaScriptException();
return;
}
if (!proofsource->AddCertificateChain(addchain, std::move(*addcertprivkey)))
{
Napi::Error::New(Env(), "AddCertificateChain failed for Http3Server").ThrowAsJavaScriptException();
return;
}
}
server_ = std::make_unique<Http3Server>(this, std::move(proofsource), secret.c_str(), sconfig);
return;
}
else
{
Napi::Error::New(Env(), "No arguments passed to Http3Server").ThrowAsJavaScriptException();
return;
}
}
Http3ServerJS::~Http3ServerJS()
{
}
void Http3ServerJS::destroy(const Napi::CallbackInfo &info)
{
server_->Destroy();
server_.reset();
}
Napi::Value Http3ServerJS::recvPaket(const Napi::CallbackInfo &info)
{
QuicTime now = QuicDefaultClock::Get()->Now();
// Got a packet replace OnSocketEvent for readable
if (info[0].IsUndefined())
{
Napi::Error::New(Env(), "No obj passed to recvPaket").ThrowAsJavaScriptException();
return Env().Undefined();
}
Napi::Object lobj = info[0].ToObject();
if (lobj.IsEmpty())
{
Napi::Error::New(Env(), "Obj for recvPaket is empty").ThrowAsJavaScriptException();
return Env().Undefined();
}
if (!lobj.Has("selfaddress"))
{
Napi::Error::New(Env(), "No Selfaddress for recvPaket").ThrowAsJavaScriptException();
return Env().Undefined();
}
Napi::Object selfaddress = (lobj).Get("selfaddress").As<Napi::Object>();
if (selfaddress.IsEmpty())
{
Napi::Error::New(Env(), "Selfaddress for recvPaket empty").ThrowAsJavaScriptException();
return Env().Undefined();
}
int port = selfaddress.Get("port").As<Napi::Number>().Int32Value();
std::string selfipaddress = selfaddress.Get("address").As<Napi::String>();
QuicIpAddress self_ip;
self_ip.FromString(selfipaddress);
QuicSocketAddress self_address(self_ip, port);
if (!lobj.Has("rinfo"))
{
Napi::Error::New(Env(), "No rinfo for recvPaket").ThrowAsJavaScriptException();
return Env().Undefined();
}
Napi::Object rinfo = (lobj).Get("rinfo").As<Napi::Object>();
if (rinfo.IsEmpty())
{
Napi::Error::New(Env(), "Rinfo for recvPaket empty").ThrowAsJavaScriptException();
return Env().Undefined();
}
int peerport = rinfo.Get("port").As<Napi::Number>().Int32Value();
std::string peeripaddress = rinfo.Get("address").As<Napi::String>();
QuicIpAddress peer_ip;
peer_ip.FromString(peeripaddress);
QuicSocketAddress peer_address(peer_ip, peerport);
Napi::Object bufferlocal = lobj.Get("msg").As<Napi::Object>();
QuicReceivedPacket packet(
bufferlocal.As<Napi::Buffer<char>>().Data(), rinfo.Get("size").As<Napi::Number>().Uint32Value(), now,
/*owns_buffer=*/false, 0 /*ttl*/, false /*has_ttl*/, nullptr /*headers*/, 0 /*headers_length*/,
/*owns_header_buffer=*/false, ECN_NOT_ECT);
Http3Server *obj = getObj();
bool hasbufferedchlos = obj->ProcessPacket(self_address, peer_address, packet);
return Napi::Boolean::New(Env(), hasbufferedchlos);
}
bool Http3Server::ProcessPacket(const QuicSocketAddress &self_address,
const QuicSocketAddress &peer_address,
const QuicReceivedPacket &packet)
{
dispatcher_.get()->ProcessPacket(self_address, peer_address, packet);
return dispatcher_->HasChlosBuffered();
}
void Http3ServerJS::processBufferedChlos(const Napi::CallbackInfo &info)
{
Http3Server *obj = getObj();
obj->ProcessBufferedChlos();
}
void Http3Server::ProcessBufferedChlos()
{
dispatcher_->ProcessBufferedChlos(kNumSessionsToCreatePerSocketEvent);
}
void Http3ServerJS::onCanWrite(const Napi::CallbackInfo &info)
{
server_->OnCanWrite();
}
void Http3Server::OnCanWrite()
{
dispatcher_->OnCanWrite();
}
/*void Http3Server::OnSocketEvent(QuicEventLoop *event_loop, QuicUdpSocketFd fd,
QuicSocketEventMask events)
{
// QUICHE_DCHECK_EQ(fd, fd_);
/* if (events & kSocketEventReadable)
{
QUIC_DVLOG(1) << "kSocketEventReadable";
dispatcher_->ProcessBufferedChlos(kNumSessionsToCreatePerSocketEvent);
bool more_to_read = true;
while (more_to_read)
{
more_to_read = packet_reader_->ReadAndDispatchPackets(
fd_, port_, *QuicDefaultClock::Get(), dispatcher_.get(),
overflow_supported_ ? &packets_dropped_ : nullptr);
}
if (dispatcher_->HasChlosBuffered())
{
// Register EPOLLIN event to consume buffered CHLO(s).
bool success =
event_loop->ArtificiallyNotifyEvent(fd, kSocketEventReadable);
QUICHE_DCHECK(success);
}
else if (!event_loop->SupportsEdgeTriggered())
{
bool success = event_loop->RearmSocket(fd, kSocketEventReadable);
QUICHE_DCHECK(success);
}
}
if (events & kSocketEventWritable)
{
dispatcher_->OnCanWrite();
if (!event_loop->SupportsEdgeTriggered() &&
dispatcher_->HasPendingWrites())
{
bool success = event_loop->RearmSocket(fd, kSocketEventWritable);
QUICHE_DCHECK(success);
}
}
}*/
void Http3ServerJS::processNewSession(Http3WTSession *session, const std::string &path, Napi::Reference<Napi::Value> *header, Napi::Reference<Napi::Value> *userData)
{
Napi::HandleScope scope(Env());
Http3Constructors *constr = Env().GetInstanceData<Http3Constructors>();
Napi::Object sessionobj = constr->session.New({});
Http3WTSessionJS *sessionjs = Napi::ObjectWrap<Http3WTSessionJS>::Unwrap(sessionobj);
sessionjs->setObj(session);
sessionjs->Ref();
session->setJS(sessionjs);
Napi::Object objVal = Value().Get("jsobj").As<Napi::Object>();
Napi::Object retObj = Napi::Object::New(Env());
retObj.Set("session", sessionobj);
retObj.Set("path", path);
if (header)
{
retObj.Set("header", header->Value());
header->Unref();
}
if (userData)
{
retObj.Set("userData", userData->Value());
userData->Unref();
}
objVal.Get("onHttpWTSessionVisitor")
.As<Napi::Function>()
.Call(objVal, {retObj});
}
void Http3ServerJS::processNewSessionRequest(WebTransportSession *session, const quiche::HttpHeaderBlock &reqhead, WebTransportRespPromisePtr promise)
{
Napi::HandleScope scope(Env());
Napi::Object objVal = Value().Get("jsobj").As<Napi::Object>();
Napi::Object retObj = Napi::Object::New(Env());
// header
Napi::Object headObj = Napi::Object::New(Env());
for (auto pair : reqhead)
{
// we iterate over all header fields
headObj.Set(std::string(pair.first), std::string(pair.second));
}
retObj.Set("header", headObj);
// delete reqheadcopy; // we own it and must free it!
WebTransportRespPromisePtr *prompointer = new WebTransportRespPromisePtr(promise);
// promise
Napi::External<WebTransportRespPromisePtr> promObj =
Napi::External<WebTransportRespPromisePtr>::New(Env(), prompointer,
[](Napi::Env /*env*/, WebTransportRespPromisePtr *ref)
{
delete ref; // we own it and must delete it
});
retObj.Set("promise", promObj);
Napi::External<WebTransportSession> wtsObj =
Napi::External<WebTransportSession>::New(Env(), session,
[](Napi::Env /*env*/, WebTransportSession *ref)
{
// we do not own it! And do not delete it.
// does it outlife everything?
});
retObj.Set("session", wtsObj);
retObj.Set("protocol", "http3:libquiche");
objVal.Get("onSessionRequest")
.As<Napi::Function>()
.Call(objVal, {retObj});
}
void Http3ServerJS::addPath(const Napi::CallbackInfo &info)
{
Http3Server *obj = getObj();
if (!info[0].IsUndefined())
{
std::string lpath(info[0].ToString().Utf8Value());
obj->http3_server_backend_.addPath(lpath);
}
else
return Napi::Error::New(Env(), "No path set for addPath").ThrowAsJavaScriptException();
}
void Http3ServerJS::finishSessionRequest(const Napi::CallbackInfo &info)
{
Http3Server *obj = getObj();
if (!info[0].IsUndefined())
{
// needs two properties
int status = -1;
std::string path = "";
Napi::Object lobj = info[0].ToObject();
if (!lobj.IsEmpty())
{
if (lobj.Has("status") && !(lobj).Get("status").IsEmpty())
{
Napi::Value statusValue = (lobj).Get("status");
status = statusValue.As<Napi::Number>().Int32Value();
}
else
return Napi::Error::New(Env(), "No status code passed for finishSessionRequest").ThrowAsJavaScriptException();
if (lobj.Has("path") && !(lobj).Get("path").IsEmpty())
{
Napi::Value pathValue = (lobj).Get("path");
path = pathValue.ToString().Utf8Value();
}
else
return Napi::Error::New(Env(), "No path passed for finishSessionRequest").ThrowAsJavaScriptException();
WebTransportSession *session = nullptr;
if (lobj.Has("session") && !(lobj).Get("session").IsEmpty())
{
Napi::Value sessionVal = (lobj).Get("session");
if (!sessionVal.IsExternal())
return Napi::Error::New(Env(), "Session is not external for finishSessionRequest").ThrowAsJavaScriptException();
Napi::External<WebTransportSession> sessionExt = sessionVal.As<Napi::External<WebTransportSession>>();
session = sessionExt.Data();
}
else
return Napi::Error::New(Env(), "No session passed for finishSessionRequest").ThrowAsJavaScriptException();
if (lobj.Has("promise") && !(lobj).Get("promise").IsEmpty())
{
Napi::Value promiseVal = (lobj).Get("promise");
if (!promiseVal.IsExternal())
return Napi::Error::New(Env(), "Promise is not external for finishSessionRequest").ThrowAsJavaScriptException();
Napi::External<Http3ServerBackend::WebTransportRespPromisePtr> promise = promiseVal.As<Napi::External<Http3ServerBackend::WebTransportRespPromisePtr>>();
Http3ServerBackend::WebTransportRespPromisePtr *prom = promise.Data();
Napi::Reference<Napi::Value> *headerValue = nullptr;
Napi::Reference<Napi::Value> *userDataValue = nullptr;
if (status == 200)
{
if (lobj.Has("header") && !(lobj).Get("header").IsEmpty())
{
napi_ref ref;
napi_status status = napi_create_reference(Env(), lobj.Get("header"), 1, &ref);
NAPI_THROW_IF_FAILED(Env(), status, Reference<Napi::Value>());
headerValue = new Napi::Reference<Napi::Value>(Env(), ref);
}
else
return Napi::Error::New(Env(), "No header passed for finishSessionRequest").ThrowAsJavaScriptException();
if (lobj.Has("userData") && !(lobj).Get("userData").IsEmpty())
{
napi_ref ref;
napi_status status = napi_create_reference(Env(), lobj.Get("userData"), 1, &ref);
NAPI_THROW_IF_FAILED(Env(), status, Reference<Napi::Value>());
userDataValue = new Napi::Reference<Napi::Value>(Env(), ref);
}
}
if (status != 200)
{
std::unique_ptr<Http3ServerBackend::WebTransportResponse> response = std::make_unique<Http3ServerBackend::WebTransportResponse>();
response->response_headers[":status"] = std::to_string(status);
(*prom)->resolve(std::move(response));
}
else
{
std::unique_ptr<Http3ServerBackend::WebTransportResponse> response = std::make_unique<Http3ServerBackend::WebTransportResponse>();
response->response_headers[":status"] = std::to_string(status);
Http3WTSession *wtsession = new Http3WTSession();
wtsession->init(session);
response->visitor =
std::make_unique<Http3WTSession::Visitor>(wtsession);
processNewSession(static_cast<Http3WTSession *>(wtsession), path, headerValue, userDataValue);
(*prom)->resolve(std::move(response));
}
}
else
return Napi::Error::New(Env(), "No promise passed for finishSessionRequest").ThrowAsJavaScriptException();
}
else
return Napi::Error::New(Env(), "No object passed for finishSessionRequest").ThrowAsJavaScriptException();
}
}
void Http3ServerJS::setJSRequestHandler(const Napi::CallbackInfo &info)
{
Http3Server *obj = getObj();
if (!info[0].IsUndefined())
{
bool hashandler = info[0].ToBoolean();
obj->http3_server_backend_.setJSHandler(hashandler);
}
else
return Napi::Error::New(Env(), "No bool set for setJSRequestHandler").ThrowAsJavaScriptException();
}
}