Specific header formats

This section describes the headers that have specific support for encoding or decoding using parts and parameters. Other headers not listed are encoded and decoded using a default mechanism that assumes the header field has a single part with a string value.

Accept

This is a client request header.

RHTTPHeaders hdr = aReq.GetHeaderCollection();
// Setting a single media range with no parameter, i.e. Accept: text/html 
RStringF textHtml = iStrTb.OpenFStringL(_L8("text/html")); 
CleanupClosePushL(textHtml);
THTTPHdrVal accVal(textHtml); 
hdr.SetFieldL(iStrTb.String(HTTP::EAccept,RHTTPSession::GetTable()), accVal); 
CleanupStack::PopAndDestroy(&textHtml);
// Setting several media ranges with no parameters, i.e. Accept: text/html; text/vnd.wap.wml 
RStringF textHtml = iStrTb.OpenFStringL(_L8("text/html")); 
CleanupClosePushL(textHtml);
RStringF textWml  = iStrTb.OpenFStringL(_L8("text/vnd.wap.wml")); 
CleanupClosePushL(textWml);
THTTPHdrVal accVal(textHtml);
hdr.SetFieldL(iStrTb.String(HTTP::EAccept,RHTTPSession::GetTable()), accVal); 
accVal.SetStr(textWml); 
hdr.SetFieldL(iStrTb.String(HTTP::EAccept,RHTTPSession::GetTable()), accVal); 
CleanupStack::PopAndDestroy(&textHtml);
CleanupStack::PopAndDestroy(&textWml);
// Setting a media range with a 'q' parameter,  Accept: text/html; q=0.8 
RStringF textHtml  = iStrTb.OpenFStringL(_L8("text/html")); 
CleanupClosePushL(textHtml);
THTTPHdrVal accVal(textHtml); 
THTTPHdrVal q(THTTPHdrVal::TQConv(0.8)); 
hdr.SetFieldL(iStrTb.String(HTTP::EAccept,RHTTPSession::GetTable()), accVal, iStrTb.String(HTTP::EQ,RHTTPSession::GetTable()), q); 
CleanupStack::PopAndDestroy(&textHtml);
// Using an accept extension,  Accept: text/html; extended=value 
RStringF textHtml  = iStrTb.OpenFStringL(_L8("text/html")); 
CleanupClosePushL(textHtml);
RStringF extended  = iStrTb.OpenFStringL(_L8("extended")); 
CleanupClosePushL(extended);
RStringF extendVal = iStrTb.OpenFStringL(_L8("value")); 
CleanupClosePushL(extendVal);

THTTPHdrVal accVal(textHtml); 
THTTPHdrVal extVal(extendVal); 

hdr.SetFieldL(iStrTb.String(HTTP::EAccept,RHTTPSession::GetTable()), accVal, extended, extVal); 
CleanupStack::PopAndDestroy(3); // textHtml, extended, extendVal

Accept-Charset

This is a client request header.

RHTTPHeaders hdr = aReq.GetHeaderCollection();
// Setting up two accepted character sets, i.e.  Accept-Charset: us-ascii, utf-8 
RStringF usAscii = iStrTb.OpenFStringL(_L8("us-ascii"));
CleanupClosePushL(usAscii);
RStringF utf8 = iStrTb.OpenFStringL(_L8("utf-8"));
CleanupClosePushL(utf8);
THTTPHdrVal accChSetVal(usAscii);
hdr.SetFieldL(iStrTb.String(HTTP::EAcceptCharset,RHTTPSession::GetTable()), accChSetVal);
// sets the first part accChSetVal.(SetStrutf8);
hdr.SetFieldL(iStrTb.String(HTTP::EAcceptCharset,RHTTPSession::GetTable()), accChSetVal);
// adds an additional part usAscii.Close();
CleanupStack::PopAndDestroy(2);

Authorisation

This is a client request header. Note: The client need not set this header for most normal requests.

RHTTPHeaders hdr = aReq.GetHeaderCollection();
// Setting an authorization credential, i.e. Authorization: Basic c3ltYmlhbjpmMXN5bmNtbA== 
RStringF basicCred = iStrTb.OpenFStringL(_L8("c3ltYmlhbjpmMXN5bmNtbA=="));
CleanupClosePushL(basicCred);
THTTPHdrVal authVal(iStrTb.String(HTTP::EBasic,RHTTPSession::GetTable()));
hdr.SetFieldL(iStrTb.String(HTTP::EAuthorization,RHTTPSession::GetTable()), authVal);
authVal.(SetStrbasicCred);
hdr.SetFieldL(iStrTb.String(HTTP::EAuthorization,RHTTPSession::GetTable()), authVal);
CleanupStack::PopAndDestroy(&basicCred);

Connection

This is a general header, that is, it applies to the connection between client and server. Note: The client need not set this header for normal, persistent HTTP/1.1 requests.

RHTTPHeaders hdr = aReq.GetHeaderCollection();
// Indicate that the connection is to close, i.e. Connection: close 
THTTPHdrVal closeVal(iStrTb.String(HTTP::EClose,RHTTPSession::GetTable()));
hdr.SetFieldL(iStrTb.String(HTTP::EConnection,RHTTPSession::GetTable()), closeVal);

Content-Length

This is an entity header, that is, it applies to the body present in a request or a response. Note: The client should not set this header for any request: it will be ignored.

RHTTPHeaders hdr = aReq.GetHeaderCollection();
// Set a content length of 12345, i.e. Content-Length: 12345 
THTTPHdrVal lengthVal(12345);
hdr.SetFieldL(iStrTb.String(HTTP::EContentLength,RHTTPSession::GetTable()), lengthVal);

Content-Type

This is an entity header, that is, it applies to the body present in a request or a response.

RHTTPHeaders hdr = aReq.GetHeaderCollection();
// Set a content type of text/html, i.e. Content-Type: text/html 
THTTPHdrVal contTypeVal(iStrTb.String(HTTP::ETextHtml,RHTTPSession::GetTable()));
hdr.SetFieldL(iStrTb.String(HTTP::EContentType,RHTTPSession::GetTable()), contTypeVal);

Date

This is a general header, that is, it applies to the connection between client and server. All three date formats specified in RFC2616 are supported in responses. Requests will be made using the RFC1123 format only.

RHTTPHeaders hdr = aReq.GetHeaderCollection();
// Set a date of 9th August 2001, time 13:45:00.000, i.e. Date: Thu, 09 Aug 2001 13:45:00 GMT 
THTTPHdrVal dateVal(TDateTime(2001, EAugust, 8, 13, 45, 0, 0));
// note, the day starts at 0 
hdr.SetFieldL(iStrTb.String(HTTP::EDate,RHTTPSession::GetTable()), dateVal);

Host

This is a client request header. Note: The client should not set this header for any request unless the URL is relative.

RHTTPHeaders hdr = aReq.GetHeaderCollection();
// Set a host 'www.symbian.com', i.e. Host: www.symbian.com 
_LIT8(host, "www.symbian.com");
RStringF hostValStr = iStrTb.OpenFStringL(host);
CleanupClosePushL(hostValStr);   
THTTPHdrVal hostVal(hostValStr);    
hdr.SetFieldL(hostStr, hostVal);
CleanupStack::PopAndDestroy(&hostValStr);

Transfer-Encoding

This is a general header, that is, it applies to the connection between client and server. Note: The client should not set this header for any request, as it will be ignored.

RHTTPHeaders hdr = aReq.GetHeaderCollection();
// Set the transfer encoding to be 'chunked', i.e. Transfer-Encoding: chunked 
THTTPHdrVal xferEncVal;
xferEncVal.SetStrF(iStrTb.StringF(HTTP::EChunked,RHTTPSession::GetTable()));
hdr.SetFieldL(iStrTb.StringF(HTTP::ETransferEncoding,RHTTPSession::GetTable()), xferEncVal);

User-Agent

This is a client request header.

RHTTPHeaders hdr = aReq.GetHeaderCollection();
// Set up a user agent with two part, i.e. User-Agent: CERN-LineMode/2.15 libwww/2.17b3 
RStringF ua1Str = iStrP.OpenFStringL(_L8("CERN-LineMode/2.15"));
CleanupClosePushL(ua1Str);
RStringF ua2Str = iStrP.OpenFStringL(_L8("libwww/2.17b3"));
CleanupClosePushL(ua2Str);
RStringF uaStr = iStrP.StringF(HTTP::EUserAgent,RHTTPSession::GetTable());
THTTPHdrVal uaVal(ua1Str);
hdr.SetFieldL(uaStr, uaVal);
// sets part 1 uaVal.SetStrF(ua2Str);
hdr.SetFieldL(uaStr, uaVal);
// sets part 2
CleanupStack::PopAndDestroy(2);

WWW-Authenticate

This is a server response header. Note: The client need not read this header for most normal responses.

RHTTPHeaders hdr = aReq.GetHeaderCollection();
...
// Display realm for WWW-Authenticate header 
RStringF wwwAuth = strP.StringF(HTTP::EWWWAuthenticate,RHTTPSession::GetTable());
            if (fieldNameStr == wwwAuth)
                {
                // check the auth scheme is 'basic'
                RStringF basic = strP.StringF(HTTP::EBasic,RHTTPSession::GetTable());
                RStringF realm = strP.StringF(HTTP::ERealm,RHTTPSession::GetTable());
                THTTPHdrVal realmVal;
                if ((fieldVal.StrF() == basic) && 
                    (!hdr.GetParam(wwwAuth, realm, realmVal)))
                    {
                    RStringF realmValStr = strP.StringF(realmVal.StrF());
                    fieldVal16.Copy(realmValStr.DesC());
                    iUtils.Test().Printf(_L("Realm is: %S\n"), &fieldVal16);
                    realmValStr.Close();
                    }
                basic.Close();
                realm.Close();
                }
            wwwAuth.Close();
hdr.Close();