MCPcopy Create free account
hub / github.com/apache/trafficserver / http_event_handler

Function http_event_handler

plugins/experimental/wasm/wasm_main.cc:374–531  ·  view source on GitHub ↗

handler for transaction event

Source from the content-addressed store, hash-verified

372
373// handler for transaction event
374static int
375http_event_handler(TSCont contp, TSEvent event, void *data)
376{
377 int result = -1;
378 auto *context = static_cast<ats_wasm::Context *>(TSContDataGet(contp));
379 auto *old_wasm = static_cast<ats_wasm::Wasm *>(context->wasm());
380
381 context->resetTxnReenable();
382
383 TSMutexLock(old_wasm->mutex());
384 std::shared_ptr<ats_wasm::Wasm> temp = nullptr;
385 auto *txnp = static_cast<TSHttpTxn>(data);
386
387 TSMBuffer buf = nullptr;
388 TSMLoc hdr_loc = nullptr;
389 int count = 0;
390
391 switch (event) {
392 case TS_EVENT_HTTP_TXN_START:
393 break;
394
395 case TS_EVENT_HTTP_READ_REQUEST_HDR:
396 if (TSHttpTxnClientReqGet(txnp, &buf, &hdr_loc) != TS_SUCCESS) {
397 TSError("[wasm][%s] cannot retrieve client request", __FUNCTION__);
398 TSMutexUnlock(old_wasm->mutex());
399 TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
400 context->setTxnReenable();
401 return 0;
402 }
403 count = TSMimeHdrFieldsCount(buf, hdr_loc);
404 TSHandleMLocRelease(buf, TS_NULL_MLOC, hdr_loc);
405
406 result = context->onRequestHeaders(count, false) == proxy_wasm::FilterHeadersStatus::Continue ? 0 : 1;
407 break;
408
409 case TS_EVENT_HTTP_POST_REMAP:
410 break;
411
412 case TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE:
413 break;
414
415 case TS_EVENT_HTTP_SEND_REQUEST_HDR:
416 break;
417
418 case TS_EVENT_HTTP_READ_RESPONSE_HDR:
419 if (TSHttpTxnServerRespGet(txnp, &buf, &hdr_loc) != TS_SUCCESS) {
420 TSError("[wasm][%s] cannot retrieve server response", __FUNCTION__);
421 TSMutexUnlock(old_wasm->mutex());
422 TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
423 context->setTxnReenable();
424 return 0;
425 }
426 count = TSMimeHdrFieldsCount(buf, hdr_loc);
427 TSHandleMLocRelease(buf, TS_NULL_MLOC, hdr_loc);
428
429 result = context->onResponseHeaders(count, false) == proxy_wasm::FilterHeadersStatus::Continue ? 0 : 1;
430 break;
431

Callers

nothing calls this directly

Calls 15

TSContDataGetFunction · 0.85
TSMutexLockFunction · 0.85
TSHttpTxnClientReqGetFunction · 0.85
TSMutexUnlockFunction · 0.85
TSHttpTxnReenableFunction · 0.85
TSMimeHdrFieldsCountFunction · 0.85
TSHandleMLocReleaseFunction · 0.85
TSHttpTxnServerRespGetFunction · 0.85
TSContDestroyFunction · 0.85
resetTxnReenableMethod · 0.80
setTxnReenableMethod · 0.80
onLocalReplyMethod · 0.80

Tested by

no test coverage detected