|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-675D02F1-E7B1-4869-9213-8D0C2E0CC50D" xml:lang="en"><title>Adding, |
|
13 Removing and Accessing Header Field Parts</title><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <section id="GUID-F273A4FC-D2C7-45A2-A2CA-12D9B6C8531C"> <p>Header field parts are added by repeated invocation of the <xref href="GUID-54F9A87B-FE2F-3429-9793-0A24B83466B9.dita#GUID-54F9A87B-FE2F-3429-9793-0A24B83466B9/GUID-A8708AE6-8EAE-37C9-BAD2-87E4A7DCE266"><apiname>RHTTPHeaders::SetFieldL()</apiname></xref> method. |
|
15 On the first invocation, when no field of that name exists in the header, |
|
16 a new field is created with a single part. On subsequent invocations, additional |
|
17 parts are added to the existing header field. </p> <p>This behaviour is consistent |
|
18 with HTTP/1.1 in which: </p> <codeblock id="GUID-16F90813-AABE-5855-A7EB-6CB4C4D52225" xml:space="preserve">Accept: text/*, text/html</codeblock> <p>is |
|
19 preferable to </p> <codeblock id="GUID-7290C356-D37B-5A79-9C11-470D500647CC" xml:space="preserve">Accept: text/* text/html</codeblock> <p>Although |
|
20 the two are semantically equivalent, the API will not output the second variant |
|
21 under any circumstance. </p> <p>When parts are added to a header field, they |
|
22 are given an index number. The first part to be added has index 0, the second |
|
23 is index 1, and so on. This index is necessary when identifying parts for |
|
24 retrieval (using <xref href="GUID-54F9A87B-FE2F-3429-9793-0A24B83466B9.dita#GUID-54F9A87B-FE2F-3429-9793-0A24B83466B9/GUID-E89FA67E-7E0B-3C37-B920-B6E594A31BFE"><apiname>RHTTPHeaders::GetField()</apiname></xref>). </p> <p>To |
|
25 remove a single header field part, <xref href="GUID-54F9A87B-FE2F-3429-9793-0A24B83466B9.dita#GUID-54F9A87B-FE2F-3429-9793-0A24B83466B9/GUID-656EF7AC-479E-3408-B00C-9FAE3022A37B"><apiname>RHTTPHeaders::RemoveFieldPart()</apiname></xref> is |
|
26 used, specifying a part index. To remove a header field entirely, <xref href="GUID-54F9A87B-FE2F-3429-9793-0A24B83466B9.dita#GUID-54F9A87B-FE2F-3429-9793-0A24B83466B9/GUID-2C6BE5F2-E486-39E9-8594-2E5A5E936C1A"><apiname>RHTTPHeaders::RemoveField()</apiname></xref> is |
|
27 used. </p> <p>Part values are accessed using <xref href="GUID-54F9A87B-FE2F-3429-9793-0A24B83466B9.dita#GUID-54F9A87B-FE2F-3429-9793-0A24B83466B9/GUID-E89FA67E-7E0B-3C37-B920-B6E594A31BFE"><apiname>RHTTPHeaders::GetField()</apiname></xref>. |
|
28 The client must supply a part index and an uninitialized <xref href="GUID-DEE8279A-3BEC-316F-97B8-6C49FEDBD5B3.dita"><apiname>THTTPHdrVal</apiname></xref>, |
|
29 which will be filled by the method. This example, from <filepath>HTTPEXAMPLECLIENT</filepath>, |
|
30 retrieves all response headers and prints their values: </p> <codeblock id="GUID-034F2800-1177-5E78-8253-134E5B2C2323" xml:space="preserve">void CHttpEventHandler::DumpRespHeadersL(RHTTPTransaction& aTrans) |
|
31 { |
|
32 RHTTPResponse resp = aTrans.Response(); |
|
33 RStringPool strP = aTrans.Session().StringPool(); |
|
34 RHTTPHeaders hdr = resp.GetHeaderCollection(); |
|
35 THTTPHdrFieldIter it = hdr.Fields(); |
|
36 |
|
37 TBuf<KMaxHeaderNameLen> fieldName16; |
|
38 TBuf<KMaxHeaderValueLen> fieldVal16; |
|
39 |
|
40 while (it.AtEnd() == EFalse) |
|
41 { |
|
42 RStringTokenF fieldName = it(); |
|
43 RStringF fieldNameStr = strP.StringF(fieldName); |
|
44 THTTPHdrVal fieldVal; |
|
45 if (hdr.GetField(fieldNameStr,0,fieldVal) == KErrNone) |
|
46 { |
|
47 const TDesC8& fieldNameDesC = fieldNameStr.DesC(); |
|
48 fieldName16.Copy(fieldNameDesC.Left(KMaxHeaderNameLen)); |
|
49 switch (fieldVal.Type()) |
|
50 { |
|
51 case THTTPHdrVal::KTIntVal: |
|
52 iUtils.Test().Printf(_L("%S: %d\n"), &fieldName16, fieldVal.Int()); |
|
53 break; |
|
54 case THTTPHdrVal::KStrFVal: |
|
55 { |
|
56 RStringF fieldValStr = strP.StringF(fieldVal.StrF()); |
|
57 const TDesC8& fieldValDesC = fieldValStr.DesC(); |
|
58 fieldVal16.Copy(fieldValDesC.Left(KMaxHeaderValueLen)); |
|
59 iUtils.Test().Printf(_L("%S: %S\n"), &fieldName16, &fieldVal16); |
|
60 fieldValStr.Close(); |
|
61 } |
|
62 break; |
|
63 case THTTPHdrVal::KStrVal: |
|
64 { |
|
65 RString fieldValStr = strP.String(fieldVal.Str()); |
|
66 const TDesC8& fieldValDesC = fieldValStr.DesC(); |
|
67 fieldVal16.Copy(fieldValDesC.Left(KMaxHeaderValueLen)); |
|
68 iUtils.Test().Printf(_L("%S: %S\n"), &fieldName16, &fieldVal16); |
|
69 fieldValStr.Close(); |
|
70 } |
|
71 break; |
|
72 case THTTPHdrVal::KDateVal: |
|
73 { |
|
74 TDateTime date = fieldVal.DateTime(); |
|
75 TBuf<40> dateTimeString; |
|
76 TTime t(date); |
|
77 t.FormatL(dateTimeString,KDateFormat); |
|
78 iUtils.Test().Printf(_L("%S: %S\n"), &fieldName16, &dateTimeString); |
|
79 } |
|
80 break; |
|
81 default: |
|
82 iUtils.Test().Printf(_L("%S: <unrecognised value type>\n"), &fieldName16); |
|
83 break; |
|
84 } |
|
85 ... |
|
86 } |
|
87 // Advance the iterator to get the next field |
|
88 ++it; |
|
89 } |
|
90 }</codeblock> <p>Note that in this example, only the first part of each |
|
91 header field is displayed. </p> </section> |
|
92 </conbody></concept> |