* @brief Append User-Agent header captures specified in the Pattern configuration object. * * Apply given PCRE pattern/replacement to the first User-Agent value, and append any captured portions to cache key. * @param config PCRE pattern which contains capture groups. * @todo: TBD if ignoring the comma in the header as a field separator is generic enough. * @note Add the UA captures to hier-p
| 682 | * @note Add the UA captures to hier-part (RFC 3986) in the original order. |
| 683 | */ |
| 684 | void |
| 685 | CacheKey::appendUaCaptures(Pattern &config) |
| 686 | { |
| 687 | if (config.empty()) { |
| 688 | return; |
| 689 | } |
| 690 | |
| 691 | TSMLoc field; |
| 692 | const char *value; |
| 693 | int len; |
| 694 | |
| 695 | field = TSMimeHdrFieldFind(_buf, _hdrs, TS_MIME_FIELD_USER_AGENT, TS_MIME_LEN_USER_AGENT); |
| 696 | if (field == TS_NULL_MLOC) { |
| 697 | CacheKeyDebug("missing %.*s header", TS_MIME_LEN_USER_AGENT, TS_MIME_FIELD_USER_AGENT); |
| 698 | return; |
| 699 | } |
| 700 | |
| 701 | /* Now, strictly speaking, the User-Agent header should not contain a comma, |
| 702 | * because that's really a field separator (RFC 2616). Unfortunately, the |
| 703 | * iOS apps will send an embedded comma and we have to deal with it as if |
| 704 | * it was a single header. */ |
| 705 | value = TSMimeHdrFieldValueStringGet(_buf, _hdrs, field, -1, &len); |
| 706 | if (value && len) { |
| 707 | String val(value, len); |
| 708 | StringVector captures; |
| 709 | |
| 710 | if (config.process(val, captures)) { |
| 711 | for (auto &capture : captures) { |
| 712 | append(capture); |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | TSHandleMLocRelease(_buf, _hdrs, field); |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * @brief Append the class name based on the User-Agent classification using the provided classifier. |
no test coverage detected