| 686 | } |
| 687 | |
| 688 | static int |
| 689 | stats_origin(TSCont contp, TSEvent /* event ATS_UNUSED */, void *edata) |
| 690 | { |
| 691 | TSCont icontp; |
| 692 | stats_state *my_state; |
| 693 | config_t *config; |
| 694 | TSHttpTxn txnp = (TSHttpTxn)edata; |
| 695 | TSMBuffer reqp; |
| 696 | TSMLoc hdr_loc = nullptr, url_loc = nullptr, accept_field = nullptr, accept_encoding_field = nullptr; |
| 697 | TSEvent reenable = TS_EVENT_HTTP_CONTINUE; |
| 698 | int path_len = 0; |
| 699 | const char *path = nullptr; |
| 700 | swoc::TextView request_path; |
| 701 | swoc::TextView request_path_suffix; |
| 702 | output_format_t format_per_path = output_format_t::JSON_OUTPUT; |
| 703 | bool path_had_explicit_format = false; |
| 704 | |
| 705 | Dbg(dbg_ctl, "in the read stuff"); |
| 706 | config = get_config(contp); |
| 707 | |
| 708 | if (TSHttpTxnClientReqGet(txnp, &reqp, &hdr_loc) != TS_SUCCESS) { |
| 709 | goto cleanup; |
| 710 | } |
| 711 | |
| 712 | if (TSHttpHdrUrlGet(reqp, hdr_loc, &url_loc) != TS_SUCCESS) { |
| 713 | goto cleanup; |
| 714 | } |
| 715 | |
| 716 | path = TSUrlPathGet(reqp, url_loc, &path_len); |
| 717 | Dbg(dbg_ctl, "Path: %.*s", path_len, path); |
| 718 | |
| 719 | if (path_len == 0) { |
| 720 | Dbg(dbg_ctl, "Empty path"); |
| 721 | goto notforme; |
| 722 | } |
| 723 | |
| 724 | request_path = swoc::TextView{path, static_cast<size_t>(path_len)}; |
| 725 | if (!request_path.starts_with(config->stats_path)) { |
| 726 | Dbg(dbg_ctl, "Not the configured path for stats: %.*s, expected: %s", path_len, path, config->stats_path.c_str()); |
| 727 | goto notforme; |
| 728 | } |
| 729 | |
| 730 | if (request_path == config->stats_path) { |
| 731 | Dbg(dbg_ctl, "Exact match for stats path: %s", config->stats_path.c_str()); |
| 732 | format_per_path = output_format_t::JSON_OUTPUT; |
| 733 | path_had_explicit_format = false; |
| 734 | } else { |
| 735 | request_path_suffix = request_path.remove_prefix(config->stats_path.length()); |
| 736 | if (request_path_suffix == "/json") { |
| 737 | format_per_path = output_format_t::JSON_OUTPUT; |
| 738 | } else if (request_path_suffix == "/csv") { |
| 739 | format_per_path = output_format_t::CSV_OUTPUT; |
| 740 | } else if (request_path_suffix == "/prometheus") { |
| 741 | format_per_path = output_format_t::PROMETHEUS_OUTPUT; |
| 742 | } else { |
| 743 | Dbg(dbg_ctl, "Unknown suffix for stats path: %.*s", static_cast<int>(request_path_suffix.length()), |
| 744 | request_path_suffix.data()); |
| 745 | goto notforme; |
nothing calls this directly
no test coverage detected