| 264 | } |
| 265 | |
| 266 | void |
| 267 | ContData::getClientState() |
| 268 | { |
| 269 | TSMBuffer req_bufp; |
| 270 | TSMLoc req_hdr_loc; |
| 271 | if (TSHttpTxnClientReqGet(txnp, &req_bufp, &req_hdr_loc) != TS_SUCCESS) { |
| 272 | TSError("[esi][%s] Error while retrieving client request", __FUNCTION__); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | if (!esi_vars) { |
| 277 | string vars_tag; |
| 278 | esi_vars = new Variables(contp, gAllowlistCookies); |
| 279 | } |
| 280 | if (!data_fetcher) { |
| 281 | string fetcher_tag; |
| 282 | data_fetcher = new HttpDataFetcherImpl(contp, client_addr, FETCHER_DEBUG_TAG); |
| 283 | } |
| 284 | if (req_bufp && req_hdr_loc) { |
| 285 | TSMBuffer bufp; |
| 286 | TSMLoc url_loc; |
| 287 | if (TSHttpTxnPristineUrlGet(txnp, &bufp, &url_loc) != TS_SUCCESS) { |
| 288 | TSError("[esi][%s] Error while retrieving hdr url", __FUNCTION__); |
| 289 | return; |
| 290 | } |
| 291 | if (url_loc) { |
| 292 | if (request_url) { |
| 293 | TSfree(request_url); |
| 294 | } |
| 295 | int length; |
| 296 | request_url = TSUrlStringGet(bufp, url_loc, &length); |
| 297 | Dbg(dbg_ctl_local, "[%s] Got request URL [%s]", __FUNCTION__, request_url ? request_url : "(null)"); |
| 298 | int query_len; |
| 299 | const char *query = TSUrlHttpQueryGet(bufp, url_loc, &query_len); |
| 300 | if (query) { |
| 301 | esi_vars->populate(query, query_len); |
| 302 | } |
| 303 | TSHandleMLocRelease(bufp, req_hdr_loc, url_loc); |
| 304 | } |
| 305 | |
| 306 | TSMLoc field_loc = TSMimeHdrFieldGet(req_bufp, req_hdr_loc, 0); |
| 307 | bool depth_field = false; |
| 308 | while (field_loc) { |
| 309 | TSMLoc next_field_loc; |
| 310 | const char *name; |
| 311 | int name_len; |
| 312 | |
| 313 | name = TSMimeHdrFieldNameGet(req_bufp, req_hdr_loc, field_loc, &name_len); |
| 314 | if (name) { |
| 315 | if (Utils::areEqual(name, name_len, MIME_FIELD_XESIDEPTH, MIME_FIELD_XESIDEPTH_LEN)) { |
| 316 | unsigned d = TSMimeHdrFieldValueUintGet(req_bufp, req_hdr_loc, field_loc, -1); |
| 317 | d = (d + 1) % 10; |
| 318 | char dstr[2]; |
| 319 | int const len = snprintf(dstr, sizeof(dstr), "%u", d); |
| 320 | |
| 321 | HttpHeader header; |
| 322 | if (len != 1) { |
| 323 | header = HttpHeader(MIME_FIELD_XESIDEPTH, MIME_FIELD_XESIDEPTH_LEN, "1", 1); |
no test coverage detected