| 62 | } |
| 63 | |
| 64 | bool |
| 65 | read_request(TSHttpTxn txnp, Config *const config, TSCont read_resp_hdr_contp) |
| 66 | { |
| 67 | DEBUG_LOG("slice read_request"); |
| 68 | TxnHdrMgr hdrmgr; |
| 69 | hdrmgr.populateFrom(txnp, TSHttpTxnClientReqGet); |
| 70 | HttpHeader const header(hdrmgr.m_buffer, hdrmgr.m_lochdr); |
| 71 | |
| 72 | if (TS_HTTP_METHOD_GET == header.method() || TS_HTTP_METHOD_HEAD == header.method() || TS_HTTP_METHOD_PURGE == header.method()) { |
| 73 | if (!header.hasKey(config->m_skip_header.data(), config->m_skip_header.size())) { |
| 74 | // check if any previous plugin has monkeyed with the transaction status |
| 75 | TSHttpStatus const txnstat = TSHttpTxnStatusGet(txnp); |
| 76 | if (TS_HTTP_STATUS_NONE != txnstat) { |
| 77 | DEBUG_LOG("txn status change detected (%d), skipping plugin\n", static_cast<int>(txnstat)); |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | if (config->hasRegex()) { |
| 82 | int urllen = 0; |
| 83 | char *const urlstr = TSHttpTxnEffectiveUrlStringGet(txnp, &urllen); |
| 84 | if (nullptr != urlstr) { |
| 85 | bool const shouldslice = config->matchesRegex(urlstr, urllen); |
| 86 | if (!shouldslice) { |
| 87 | DEBUG_LOG("request failed regex, not slicing: '%.*s'", urllen, urlstr); |
| 88 | TSfree(urlstr); |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | DEBUG_LOG("request passed regex, slicing: '%.*s'", urllen, urlstr); |
| 93 | TSfree(urlstr); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | DEBUG_LOG("slice accepting and slicing"); |
| 98 | // connection back into ATS |
| 99 | sockaddr const *const ip = TSHttpTxnClientAddrGet(txnp); |
| 100 | if (nullptr == ip) { |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | TSAssert(nullptr != config); |
| 105 | std::unique_ptr<Data> data = std::make_unique<Data>(config); |
| 106 | |
| 107 | data->m_method_type = header.method(); |
| 108 | data->m_txnp = txnp; |
| 109 | |
| 110 | // set up feedback connect |
| 111 | if (AF_INET == ip->sa_family) { |
| 112 | memcpy(&data->m_client_ip, ip, sizeof(sockaddr_in)); |
| 113 | } else if (AF_INET6 == ip->sa_family) { |
| 114 | memcpy(&data->m_client_ip, ip, sizeof(sockaddr_in6)); |
| 115 | } else if (AF_UNIX == ip->sa_family) { |
| 116 | memcpy(&data->m_client_ip, ip, sizeof(sockaddr_un)); |
| 117 | } else { |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | // need to reset the HOST field for global plugin |
no test coverage detected