std::string CHttpHeader::GetValue(const std::string& strParam) const { std::string paramLower(strParam); StringUtils::ToLower(paramLower); return GetValueRaw(paramLower); }
std::string CHttpHeader::GetMimeType(void) const { std::string strValue(GetValueRaw("content-type")); std::string mimeType(strValue, 0, strValue.find(';')); StringUtils::TrimRight(mimeType, m_whitespaceChars); return mimeType; }
std::string CHttpHeader::GetCharset(void) const { std::string strValue(GetValueRaw("content-type")); if (strValue.empty()) return strValue; StringUtils::ToUpper(strValue); const size_t len = strValue.length(); // extract charset value from 'contenttype/contentsubtype;pram1=param1Val ; charset=XXXX\t;param2=param2Val' // most common form: 'text/html; charset=XXXX' // charset value can be in double quotes: 'text/xml; charset="XXX XX"' size_t pos = strValue.find(';'); while (pos < len) { // move to the next non-whitespace character pos = strValue.find_first_not_of(m_whitespaceChars, pos + 1); if (pos != std::string::npos) { if (strValue.compare(pos, 8, "CHARSET=", 8) == 0) { pos += 8; // move position to char after 'CHARSET=' size_t len = strValue.find(';', pos); if (len != std::string::npos) len -= pos; std::string charset(strValue, pos, len); // intentionally ignoring possible ';' inside quoted string // as we don't support any charset with ';' in name StringUtils::Trim(charset, m_whitespaceChars); if (!charset.empty()) { if (charset[0] != '"') return charset; else { // charset contains quoted string (allowed according to RFC 2616) StringUtils::Replace(charset, "\\", ""); // unescape chars, ignoring possible '\"' and '\\' const size_t closingQ = charset.find('"', 1); if (closingQ == std::string::npos) return ""; // no closing quote return charset.substr(1, closingQ - 1); } } } pos = strValue.find(';', pos); // find next parameter } } return ""; // no charset is detected }
std::string CHttpHeader::GetCharset(void) const { std::string strValue(GetValueRaw("content-type")); if (strValue.empty()) return strValue; const size_t semicolonPos = strValue.find(';'); if (semicolonPos == std::string::npos) return ""; StringUtils::ToUpper(strValue); size_t posCharset; if ((posCharset = strValue.find("; CHARSET=", semicolonPos)) != std::string::npos) posCharset += 10; else if ((posCharset = strValue.find(";CHARSET=", semicolonPos)) != std::string::npos) posCharset += 9; else return ""; return strValue.substr(posCharset, strValue.find(';', posCharset) - posCharset); }
std::string CHttpHeader::GetMimeType(void) const { std::string strValue(GetValueRaw("content-type")); return strValue.substr(0, strValue.find(';')); }