NS_IMETHODIMP HttpBaseChannel::SetContentType(const nsACString& aContentType) { if (mListener || mWasOpened) { if (!mResponseHead) return NS_ERROR_NOT_AVAILABLE; nsCAutoString contentTypeBuf, charsetBuf; bool hadCharset; net_ParseContentType(aContentType, contentTypeBuf, charsetBuf, &hadCharset); mResponseHead->SetContentType(contentTypeBuf); // take care not to stomp on an existing charset if (hadCharset) mResponseHead->SetContentCharset(charsetBuf); } else { // We are being given a content-type hint. bool dummy; net_ParseContentType(aContentType, mContentTypeHint, mContentCharsetHint, &dummy); } return NS_OK; }
NS_IMETHODIMP nsPartChannel::SetContentType(const nsACString &aContentType) { bool dummy; net_ParseContentType(aContentType, mContentType, mContentCharset, &dummy); return NS_OK; }
void nsHttpResponseHead::ParseHeaderLine(const char *line) { nsHttpAtom hdr = {0}; char *val; mHeaders.ParseHeaderLine(line, &hdr, &val); // leading and trailing LWS has been removed from |val| // handle some special case headers... if (hdr == nsHttp::Content_Length) { PRInt64 len; // permit only a single value here. if (nsHttp::ParseInt64(val, &len)) mContentLength = len; else LOG(("invalid content-length!\n")); } else if (hdr == nsHttp::Content_Type) { LOG(("ParseContentType [type=%s]\n", val)); PRBool dummy; net_ParseContentType(nsDependentCString(val), mContentType, mContentCharset, &dummy); } else if (hdr == nsHttp::Cache_Control) ParseCacheControl(val); else if (hdr == nsHttp::Pragma) ParsePragma(val); }
NS_IMETHODIMP nsBaseChannel::SetContentType(const nsACString &aContentType) { // mContentCharset is unchanged if not parsed bool dummy; net_ParseContentType(aContentType, mContentType, mContentCharset, &dummy); return NS_OK; }
// nsINetUtil interface NS_IMETHODIMP nsIOService::ParseContentType(const nsACString &aTypeHeader, nsACString &aCharset, bool *aHadCharset, nsACString &aContentType) { net_ParseContentType(aTypeHeader, aContentType, aCharset, aHadCharset); return NS_OK; }
NS_IMETHODIMP nsIOService::ExtractCharsetFromContentType(const nsACString &aTypeHeader, nsACString &aCharset, int32_t *aCharsetStart, int32_t *aCharsetEnd, bool *aHadCharset) { nsAutoCString ignored; net_ParseContentType(aTypeHeader, ignored, aCharset, aHadCharset, aCharsetStart, aCharsetEnd); if (*aHadCharset && *aCharsetStart == *aCharsetEnd) { *aHadCharset = false; } return NS_OK; }
nsresult nsHttpResponseHead::ParseHeaderLine(const char *line) { nsHttpAtom hdr = {0}; char *val; nsresult rv; rv = mHeaders.ParseHeaderLine(line, &hdr, &val); if (NS_FAILED(rv)) return rv; // leading and trailing LWS has been removed from |val| // handle some special case headers... if (hdr == nsHttp::Content_Length) { int64_t len; const char *ignored; // permit only a single value here. if (nsHttp::ParseInt64(val, &ignored, &len)) { mContentLength = len; } else { // If this is a negative content length then just ignore it LOG(("invalid content-length! %s\n", val)); } } else if (hdr == nsHttp::Content_Type) { LOG(("ParseContentType [type=%s]\n", val)); bool dummy; net_ParseContentType(nsDependentCString(val), mContentType, mContentCharset, &dummy); } else if (hdr == nsHttp::Cache_Control) ParseCacheControl(val); else if (hdr == nsHttp::Pragma) ParsePragma(val); return NS_OK; }
nsresult nsHttpResponseHead::ParseHeaderLine(const char *line) { nsHttpAtom hdr = {0}; char *val; nsresult rv; rv = mHeaders.ParseHeaderLine(line, &hdr, &val); if (NS_FAILED(rv)) return rv; // leading and trailing LWS has been removed from |val| // handle some special case headers... if (hdr == nsHttp::Content_Length) { PRInt64 len; // permit only a single value here. if (nsHttp::ParseInt64(val, &len)) { mContentLength = len; } else { LOG(("invalid content-length!\n")); return NS_ERROR_CORRUPTED_CONTENT; } } else if (hdr == nsHttp::Content_Type) { LOG(("ParseContentType [type=%s]\n", val)); PRBool dummy; net_ParseContentType(nsDependentCString(val), mContentType, mContentCharset, &dummy); } else if (hdr == nsHttp::Cache_Control) ParseCacheControl(val); else if (hdr == nsHttp::Pragma) ParsePragma(val); return NS_OK; }