コード例 #1
0
PassRefPtr<MIMEHeader> MIMEHeader::parseHeader(SharedBufferChunkReader* buffer)
{
    RefPtr<MIMEHeader> mimeHeader = adoptRef(new MIMEHeader);
    KeyValueMap keyValuePairs = retrieveKeyValuePairs(buffer);
    KeyValueMap::iterator mimeParametersIterator = keyValuePairs.find("content-type");
    if (mimeParametersIterator != keyValuePairs.end()) {
        ParsedContentType parsedContentType(mimeParametersIterator->value);
        mimeHeader->m_contentType = parsedContentType.mimeType();
        if (!mimeHeader->isMultipart())
            mimeHeader->m_charset = parsedContentType.charset().stripWhiteSpace();
        else {
            mimeHeader->m_multipartType = parsedContentType.parameterValueForName("type");
            mimeHeader->m_endOfPartBoundary = parsedContentType.parameterValueForName("boundary");
            if (mimeHeader->m_endOfPartBoundary.isNull()) {
                LOG_ERROR("No boundary found in multipart MIME header.");
                return 0;
            }
            mimeHeader->m_endOfPartBoundary.insert("--", 0);
            mimeHeader->m_endOfDocumentBoundary = mimeHeader->m_endOfPartBoundary;
            mimeHeader->m_endOfDocumentBoundary.append("--");
        }
    }

    mimeParametersIterator = keyValuePairs.find("content-transfer-encoding");
    if (mimeParametersIterator != keyValuePairs.end())
        mimeHeader->m_contentTransferEncoding = parseContentTransferEncoding(mimeParametersIterator->value);

    mimeParametersIterator = keyValuePairs.find("content-location");
    if (mimeParametersIterator != keyValuePairs.end())
        mimeHeader->m_contentLocation = mimeParametersIterator->value;

    return mimeHeader.release();
}
コード例 #2
0
ファイル: MHTMLParser.cpp プロジェクト: mirror/chromium
MIMEHeader* MIMEHeader::parseHeader(SharedBufferChunkReader* buffer) {
  MIMEHeader* mimeHeader = MIMEHeader::create();
  KeyValueMap keyValuePairs = retrieveKeyValuePairs(buffer);
  KeyValueMap::iterator mimeParametersIterator =
      keyValuePairs.find("content-type");
  if (mimeParametersIterator != keyValuePairs.end()) {
    ParsedContentType parsedContentType(mimeParametersIterator->value);
    mimeHeader->m_contentType = parsedContentType.mimeType();
    if (!mimeHeader->isMultipart()) {
      mimeHeader->m_charset = parsedContentType.charset().stripWhiteSpace();
    } else {
      mimeHeader->m_multipartType =
          parsedContentType.parameterValueForName("type");
      mimeHeader->m_endOfPartBoundary =
          parsedContentType.parameterValueForName("boundary");
      if (mimeHeader->m_endOfPartBoundary.isNull()) {
        DVLOG(1) << "No boundary found in multipart MIME header.";
        return nullptr;
      }
      mimeHeader->m_endOfPartBoundary.insert("--", 0);
      mimeHeader->m_endOfDocumentBoundary = mimeHeader->m_endOfPartBoundary;
      mimeHeader->m_endOfDocumentBoundary.append("--");
    }
  }

  mimeParametersIterator = keyValuePairs.find("content-transfer-encoding");
  if (mimeParametersIterator != keyValuePairs.end())
    mimeHeader->m_contentTransferEncoding =
        parseContentTransferEncoding(mimeParametersIterator->value);

  mimeParametersIterator = keyValuePairs.find("content-location");
  if (mimeParametersIterator != keyValuePairs.end())
    mimeHeader->m_contentLocation = mimeParametersIterator->value;

  // See rfc2557 - section 8.3 - Use of the Content-ID header and CID URLs.
  mimeParametersIterator = keyValuePairs.find("content-id");
  if (mimeParametersIterator != keyValuePairs.end())
    mimeHeader->m_contentID = mimeParametersIterator->value;

  return mimeHeader;
}