HttpTransact::perform_accept_encoding_filtering(State* s)
{
  HttpUserAgent_RegxEntry *uae;
  HTTPHdr *client_request;
  MIMEField *accept_field;
  MIMEField *usragent_field;
  char tmp_ua_buf[1024], *c;
  char const *u_agent = NULL;
  int u_agent_len = 0;
  bool retcode = false;
  bool ua_match = false;

  client_request = &s->hdr_info.client_request;

  // Make sense to check Accept-Encoding if UserAgent is present (and matches)
  if ((usragent_field = client_request->field_find(MIME_FIELD_USER_AGENT, MIME_LEN_USER_AGENT)) != 0 &&
      (u_agent = usragent_field->value_get(&u_agent_len)) != 0 && u_agent_len > 0) {
    if (u_agent_len >= (int) sizeof(tmp_ua_buf))
      u_agent_len = (int) (sizeof(tmp_ua_buf) - 1);
    memcpy(tmp_ua_buf, u_agent, u_agent_len);
    tmp_ua_buf[u_agent_len] = '\0';

    // TODO: Do we really want to do these hardcoded checks still?
    // Check hardcoded case MSIE>6 & Mozilla>4
    if ((c = strstr(tmp_ua_buf, "MSIE")) != NULL) {
      if (c[5] >= '7' && c[5] <= '9')
        return false;           // Don't change anything for IE > 6
      ua_match = true;
    } else if (!strncasecmp(tmp_ua_buf, "mozilla", 7)) {
      if (tmp_ua_buf[8] >= '5' && tmp_ua_buf[8] <= '9')
        return false;           // Don't change anything for Mozilla > 4
      ua_match = true;
    }

    // Check custom filters
    if (!ua_match && HttpConfig::user_agent_list) {
      for (uae = HttpConfig::user_agent_list; uae && !ua_match; uae = uae->next) {
        switch (uae->stype) {
        case HttpUserAgent_RegxEntry::STRTYPE_SUBSTR_CASE:     /* .substring, .string */
          if (u_agent_len >= uae->user_agent_str_size &&
              !memcmp(tmp_ua_buf, uae->user_agent_str, uae->user_agent_str_size))
            ua_match = true;
          break;
        case HttpUserAgent_RegxEntry::STRTYPE_SUBSTR_NCASE:    /* .substring_ncase, .string_ncase */
          if (u_agent_len >= uae->user_agent_str_size &&
              !strncasecmp(uae->user_agent_str, tmp_ua_buf, uae->user_agent_str_size))
            ua_match = true;
          break;
        case HttpUserAgent_RegxEntry::STRTYPE_REGEXP:  /* .regexp POSIX regular expression */
          if (uae->regx_valid && !pcre_exec(uae->regx, NULL, tmp_ua_buf, u_agent_len, 0, 0, NULL, 0))
            ua_match = true;
          break;
        default:               /* unknown type in the structure - bad initialization - impossible bug! */
          /* I can use ink_error() here since we should shutdown TS immediately */
          ink_error
            ("[HttpTransact::perform_accept_encoding_filtering] - get unknown User-Agent string type - bad initialization");
        };
      }
    }

    /* If we have correct User-Agent header ....
       Just set Accept-Encoding: identity or .... do nothing because
       "If no Accept-Encoding field is present in a request, the server MAY assume that the client
       will accept any content coding. In this case, if "identity" is one of the available content-codings,
       then the server SHOULD use the "identity" content-coding, unless it has additional information that
       a different content-coding is meaningful to the client." */
    if (ua_match) {
      DebugTxn("http_trans", "HttpTransact::ModifyRequest, insert identity Accept-Encoding");
      accept_field = client_request->field_find(MIME_FIELD_ACCEPT_ENCODING, MIME_LEN_ACCEPT_ENCODING);
      if (!accept_field) {
        accept_field = client_request->field_create(MIME_FIELD_ACCEPT_ENCODING, MIME_LEN_ACCEPT_ENCODING);
        if (accept_field)
          client_request->field_attach(accept_field);
      }
      if (accept_field) {
        client_request->field_value_set(accept_field, HTTP_VALUE_IDENTITY, HTTP_LEN_IDENTITY);
      }
    }
    retcode = true;
  }                             // end of 'user-agent'
  return retcode;
}