Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Private Member Functions | Private Attributes
nsHttpHeaderArray Class Reference

#include <nsHttpHeaderArray.h>

List of all members.

Classes

struct  nsEntry

Public Member Functions

 nsHttpHeaderArray ()
 ~nsHttpHeaderArray ()
const char * PeekHeader (nsHttpAtom header)
nsresult SetHeader (nsHttpAtom header, const nsACString &value, PRBool merge=PR_FALSE)
nsresult GetHeader (nsHttpAtom header, nsACString &value)
void ClearHeader (nsHttpAtom h)
nsresult VisitHeaders (nsIHttpHeaderVisitor *visitor)
void ParseHeaderLine (char *line, nsHttpAtom *header=nsnull, char **value=nsnull)
void Flatten (nsACString &, PRBool pruneProxyHeaders=PR_FALSE)
PRUint32 Count ()
const char * PeekHeaderAt (PRUint32 i, nsHttpAtom &header)
void Clear ()

Private Member Functions

PRInt32 LookupEntry (nsHttpAtom header, nsEntry **)
PRBool CanAppendToHeader (nsHttpAtom header)

Private Attributes

nsAutoVoidArray mHeaders

Detailed Description

Definition at line 49 of file nsHttpHeaderArray.h.


Constructor & Destructor Documentation

Definition at line 52 of file nsHttpHeaderArray.h.

{}

Definition at line 53 of file nsHttpHeaderArray.h.

{ Clear(); }

Here is the call graph for this function:


Member Function Documentation

Definition at line 252 of file nsHttpHeaderArray.cpp.

{
    return header != nsHttp::Content_Type        &&
           header != nsHttp::Content_Length      &&
           header != nsHttp::User_Agent          &&
           header != nsHttp::Referer             &&
           header != nsHttp::Host                &&
           header != nsHttp::Authorization       &&
           header != nsHttp::Proxy_Authorization &&
           header != nsHttp::If_Modified_Since   &&
           header != nsHttp::If_Unmodified_Since &&
           header != nsHttp::From                &&
           header != nsHttp::Location            &&
           header != nsHttp::Max_Forwards;
}

Here is the caller graph for this function:

Definition at line 226 of file nsHttpHeaderArray.cpp.

{
    PRInt32 i, count = mHeaders.Count();
    for (i=0; i<count; ++i)
        delete (nsEntry *) mHeaders[i];
    mHeaders.Clear();
}

Here is the caller graph for this function:

Definition at line 98 of file nsHttpHeaderArray.cpp.

{
    nsEntry *entry = nsnull;
    PRInt32 index;

    index = LookupEntry(header, &entry);
    if (entry) {
        mHeaders.RemoveElementAt(index);
        delete entry;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 69 of file nsHttpHeaderArray.h.

{ return (PRUint32) mHeaders.Count(); }

Here is the caller graph for this function:

void nsHttpHeaderArray::Flatten ( nsACString &  buf,
PRBool  pruneProxyHeaders = PR_FALSE 
)

Definition at line 198 of file nsHttpHeaderArray.cpp.

{
    PRInt32 i, count = mHeaders.Count();
    for (i=0; i<count; ++i) {
        nsEntry *entry = (nsEntry *) mHeaders[i];
        // prune proxy headers if requested
        if (pruneProxyHeaders && ((entry->header == nsHttp::Proxy_Authorization) || 
                                  (entry->header == nsHttp::Proxy_Connection)))
            continue;
        buf.Append(entry->header);
        buf.AppendLiteral(": ");
        buf.Append(entry->value);
        buf.AppendLiteral("\r\n");
    }
}

Here is the caller graph for this function:

nsresult nsHttpHeaderArray::GetHeader ( nsHttpAtom  header,
nsACString &  value 
)

Definition at line 119 of file nsHttpHeaderArray.cpp.

{
    nsEntry *entry = nsnull;
    LookupEntry(header, &entry);
    if (!entry)
        return NS_ERROR_NOT_AVAILABLE;
    result = entry->value;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsHttpHeaderArray::LookupEntry ( nsHttpAtom  header,
nsEntry **  entry 
) [private]

Definition at line 239 of file nsHttpHeaderArray.cpp.

{
    PRInt32 i, count = mHeaders.Count();
    for (i=0; i<count; ++i) {
        *entry = (nsEntry *) mHeaders[i];
        if ((*entry)->header == header)
            return i;
    }
    *entry = nsnull;
    return -1;
}

Here is the caller graph for this function:

void nsHttpHeaderArray::ParseHeaderLine ( char *  line,
nsHttpAtom header = nsnull,
char **  value = nsnull 
)

Definition at line 143 of file nsHttpHeaderArray.cpp.

{
    //
    // BNF from section 4.2 of RFC 2616:
    //
    //   message-header = field-name ":" [ field-value ]
    //   field-name     = token
    //   field-value    = *( field-content | LWS )
    //   field-content  = <the OCTETs making up the field-value
    //                     and consisting of either *TEXT or combinations
    //                     of token, separators, and quoted-string>
    //
    
    // We skip over mal-formed headers in the hope that we'll still be able to
    // do something useful with the response.

    char *p = (char *) strchr(line, ':');
    if (!p) {
        LOG(("malformed header [%s]: no colon\n", line));
        return;
    }

    // make sure we have a valid token for the field-name
    if (!nsHttp::IsValidToken(line, p)) {
        LOG(("malformed header [%s]: field-name not a token\n", line));
        return;
    }
    
    *p = 0; // null terminate field-name

    nsHttpAtom atom = nsHttp::ResolveAtom(line);
    if (!atom) {
        LOG(("failed to resolve atom [%s]\n", line));
        return;
    }

    // skip over whitespace
    p = net_FindCharNotInSet(++p, HTTP_LWS);

    // trim trailing whitespace - bug 86608
    char *p2 = net_RFindCharNotInSet(p, HTTP_LWS);

    *++p2 = 0; // null terminate header value; if all chars starting at |p|
               // consisted of LWS, then p2 would have pointed at |p-1|, so
               // the prefix increment is always valid.

    // assign return values
    if (hdr) *hdr = atom;
    if (val) *val = p;

    // assign response header
    SetHeader(atom, nsDependentCString(p, p2 - p), PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 111 of file nsHttpHeaderArray.cpp.

{
    nsEntry *entry = nsnull;
    LookupEntry(header, &entry);
    return entry ? entry->value.get() : nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 215 of file nsHttpHeaderArray.cpp.

{
    nsEntry *entry = (nsEntry *) mHeaders[index]; 
    if (!entry)
        return nsnull;

    header = entry->header;
    return entry->value.get();
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHttpHeaderArray::SetHeader ( nsHttpAtom  header,
const nsACString &  value,
PRBool  merge = PR_FALSE 
)

Definition at line 48 of file nsHttpHeaderArray.cpp.

{
    nsEntry *entry = nsnull;
    PRInt32 index;

    index = LookupEntry(header, &entry);

    // If an empty value is passed in, then delete the header entry...
    // unless we are merging, in which case this function becomes a NOP.
    if (value.IsEmpty()) {
        if (!merge && entry) {
            mHeaders.RemoveElementAt(index);
            delete entry;
        }
        return NS_OK;
    }

    // Create a new entry, or...
    if (!entry) {
        entry = new nsEntry(header, value);
        if (!entry)
            return NS_ERROR_OUT_OF_MEMORY;
        if (!mHeaders.AppendElement(entry)) {
            NS_WARNING("AppendElement failed");
            delete entry;
        }
    }
    // Append the new value to the existing value iff...
    else if (merge && CanAppendToHeader(header)) {
        if (header == nsHttp::Set_Cookie ||
            header == nsHttp::WWW_Authenticate ||
            header == nsHttp::Proxy_Authenticate)
            // Special case these headers and use a newline delimiter to
            // delimit the values from one another as commas may appear
            // in the values of these headers contrary to what the spec says.
            entry->value.Append('\n');
        else
            // Delimit each value from the others using a comma (per HTTP spec)
            entry->value.AppendLiteral(", ");
        entry->value.Append(value);
    }
    // Replace the existing string with the new value
    else
        entry->value = value;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 130 of file nsHttpHeaderArray.cpp.

{
    NS_ENSURE_ARG_POINTER(visitor);
    PRInt32 i, count = mHeaders.Count();
    for (i=0; i<count; ++i) {
        nsEntry *entry = (nsEntry *) mHeaders[i];
        if (NS_FAILED(visitor->VisitHeader(nsDependentCString(entry->header), entry->value)))
            break;
    }
    return NS_OK;
}

Member Data Documentation

nsAutoVoidArray nsHttpHeaderArray::mHeaders [private]

Definition at line 89 of file nsHttpHeaderArray.h.


The documentation for this class was generated from the following files: