|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __RHTTPHEADERS_H__ |
|
17 #define __RHTTPHEADERS_H__ |
|
18 |
|
19 // System includes |
|
20 #include <http/thttphdrfielditer.h> |
|
21 #include <http/thttphdrval.h> |
|
22 |
|
23 |
|
24 class RHTTPHeaders |
|
25 /** |
|
26 The collection of headers (or more correctly, header fields) |
|
27 associated with a message. Header (fields) can be created, read and |
|
28 modified. They may be composed of several parts (by repeated |
|
29 invocations of API methods, see below) and may be assigned one or |
|
30 more parameters. Individual field parts and parameters take |
|
31 values described using THTTPHdrVal. |
|
32 @publishedAll |
|
33 @released |
|
34 @see RHTTPMessage |
|
35 @see THTTPHdrVal |
|
36 */ |
|
37 { |
|
38 public: |
|
39 /** Default constructor |
|
40 */ |
|
41 inline RHTTPHeaders(); |
|
42 |
|
43 /**Getter methods |
|
44 Methods for reading data. |
|
45 */ |
|
46 //@{ |
|
47 /** Obtain the number of parts in the named header field's value, |
|
48 Simple headers are created with a single part following one |
|
49 call to SetFieldL. Subsequent calls to SetFieldL create |
|
50 additional parts if the field exists already. |
|
51 @leave KErrNoMemory |
|
52 @param aFieldName The header name |
|
53 @return The number of parts, or zero if the field does not exist. */ |
|
54 IMPORT_C TInt FieldPartsL(RStringF aFieldName) const; |
|
55 |
|
56 /** Obtain the named header field's value. The index |
|
57 of a part within the field must be specified. Parts are indexed |
|
58 from 0 and fields with only one part return the entire field for index 0 |
|
59 @param aFieldName The header name |
|
60 @param aPartIdx The index of the part |
|
61 @param aHeaderValue The header field value |
|
62 @return An error condition. Returns KErrNotFound if there is not a field with the |
|
63 specifed field name |
|
64 */ |
|
65 IMPORT_C TInt GetField(RStringF aFieldName, |
|
66 TInt aPartIdx, THTTPHdrVal& aHeaderValue) const; |
|
67 |
|
68 /** Obtain an Raw representation of the named header |
|
69 field's value. Note that general client use of this method is |
|
70 strongly discouraged since it exposes the Raw representation of particular headers. |
|
71 However it may be needed for some cases where received headers could not be |
|
72 decoded by HTTP. It will normally be used internally when |
|
73 preparing header data to be transmitted with a request. |
|
74 @param aFieldName The field name, e.g, 'Content-Type' |
|
75 @param aRawFieldData The field's data content, in an appropriate Raw form |
|
76 @return An error condition. Returns KErrNotFound if there is not a field with the |
|
77 specifed field name |
|
78 */ |
|
79 IMPORT_C TInt GetRawField(RStringF aFieldName, |
|
80 TPtrC8& aRawFieldData) const; |
|
81 |
|
82 /** Obtain the value of a named parameter, associated with the |
|
83 named header field. An optional index to a part within the |
|
84 header field may be supplied, if not it is assumed that it is |
|
85 the first part. |
|
86 @param aFieldName The header name |
|
87 @param aParamName The parameter name |
|
88 @param aReturn The returned value. Note that this |
|
89 must be Copy()d by the caller, if it wants to keep the value. |
|
90 @param aPartIdx The optional index of the part |
|
91 @return An error condition. Returns KErrNotFound if there is not a field with the |
|
92 specifed field name */ |
|
93 IMPORT_C TInt GetParam(RStringF aFieldName, |
|
94 RStringF aParamName, |
|
95 THTTPHdrVal& aReturn, |
|
96 TInt aPartIdx = 0) const; |
|
97 |
|
98 /** Access the fields within this header collection, via an |
|
99 iterator. Each application of the iterator returns the name |
|
100 of the next field type. This may then be accessed via |
|
101 RHTTPHeaders methods. |
|
102 @return The iterator. */ |
|
103 IMPORT_C THTTPHdrFieldIter Fields() const; |
|
104 //@} |
|
105 |
|
106 /** Setter Methods |
|
107 Methods for writing data. |
|
108 */ |
|
109 //@{ |
|
110 /** Set a named field in the header. On the first instance that |
|
111 this API method is used for a given field name, the first will |
|
112 be created. On subsequent calls, the same field will be |
|
113 extended to have several parts, with a new part created to |
|
114 hold the supplied value. |
|
115 @param aFieldName The field name, e.g, 'Content-Type' |
|
116 @param aFieldValue The field value, e.g. 'text/html' */ |
|
117 IMPORT_C void SetFieldL(RStringF aFieldName, THTTPHdrVal aFieldValue); |
|
118 |
|
119 /** Set a named field in the header, and associate with it the |
|
120 supplied parameter. If the field doesn't already exist it will |
|
121 be created along with a parameter; if it does exist, then a |
|
122 new part will be created along with the parameter. |
|
123 @param aFieldName The field name, e.g. 'Accept' |
|
124 @param aFieldValue The field value. e.g. 'text/plain' |
|
125 @param aParamName The parameter name, e.g. 'q' |
|
126 @param aParamValue The parameter value, e.g. '0.3' */ |
|
127 IMPORT_C void SetFieldL(RStringF aFieldName, THTTPHdrVal aFieldValue, |
|
128 RStringF aParamName, THTTPHdrVal aParamValue); |
|
129 |
|
130 /** Set a parameter in an existing header. |
|
131 @param aFieldName The field name, e.g. 'Accept' |
|
132 @param aPartIdx The part of the header to add the parameter to |
|
133 @param aParamName The parameter name, e.g. 'q' |
|
134 @param aParamValue The parameter value, e.g. '0.3' |
|
135 @leave KErrNotFoud if the field, or the part within the field doesn't exist |
|
136 */ |
|
137 IMPORT_C void SetParamL(RStringF aFieldName, RStringF aParamName, THTTPHdrVal aParamValue, TInt aPartIdx); |
|
138 |
|
139 /** Set a named field in the header to contain the supplied Raw header |
|
140 data. If the header already exists then a LF and the new data will be added to the existing data. This is used to |
|
141 indicate that there are multiple instances of this header |
|
142 |
|
143 |
|
144 Note that general client use of this method is strongly |
|
145 discouraged since it exposes the raw representation of particular headers. |
|
146 However it may be needed for some cases where headers to be transmitted have no encoding known |
|
147 to HTTP. It will normally be used internally when receiving data from a service provider. |
|
148 @param aFieldName The field name, e.g, 'Content-Type' |
|
149 @param aRawFieldData The field's data content, in a raw form |
|
150 @param aFieldSeparator The header field separator |
|
151 */ |
|
152 IMPORT_C void SetRawFieldL(RStringF aFieldName, |
|
153 const TDesC8& aRawFieldData, |
|
154 const TDesC8& aFieldSeparator); |
|
155 |
|
156 /** Remove, entirely, the named header field from the header |
|
157 collection. All its parts and associated parameters (where |
|
158 they exist) are also removed. |
|
159 @param aFieldName The field name. |
|
160 @return KErrNone if the removal is successful; KErrNotFound if |
|
161 the field didn't exist within the headers. */ |
|
162 IMPORT_C TInt RemoveField(RStringF aFieldName); |
|
163 |
|
164 /** Remove a single part of a header field. Just the part and any associated paramters are removed. If this |
|
165 results in no parts being present in the header then it will also be removed |
|
166 @param aFieldName The header name |
|
167 @param aIndex The particular part of the field to be removed |
|
168 @return KErrNone if the removal is sucessful; KErrNotFound if the header didn't exist. No exception is raised if |
|
169 the particular value is not found as part of that header */ |
|
170 IMPORT_C TInt RemoveFieldPart(RStringF aFieldName, TInt aIndex); |
|
171 |
|
172 /** Remove all the fields of this header collection |
|
173 */ |
|
174 IMPORT_C void RemoveAllFields(); |
|
175 |
|
176 //@} |
|
177 |
|
178 |
|
179 private: |
|
180 friend class CHeaders; |
|
181 CHeaders* iImplementation; |
|
182 }; |
|
183 |
|
184 |
|
185 inline RHTTPHeaders::RHTTPHeaders() |
|
186 : iImplementation(NULL) |
|
187 { |
|
188 } |
|
189 |
|
190 |
|
191 #endif // __RHTTPHEADERS_H__ |