Adding, removing, and accessing header field parameters

Parameters can be associated with header field parts at the time of adding the part. There are two variants of RHTTPHeaders::SetFieldL() : the first is described previously. The second variant takes four parameters, of which two specify the part name/value and two specify the parameter name/value.

To associate more than one parameter with the part, the function must be invoked repeatedly. This does not create duplicate parts; rather it locates the part with the specified value, and then adds additional parameters.

To remove parameters from header parts, the entire part must be removed using RHTTPHeaders::RemoveFieldPart() , and then added again.

To access parameter values, the header name and parameter name must be specified. RHTTPHeaders::GetParam() is used, and has an optional fourth parameter in which the part index can be provided. If not, the API assumes that the first header part contains the parameter.

The following code from HTTPEXAMPLECLIENT illustrates the use of header parameters with the WWW-Authenticate header:

       
        
       
       // 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();