|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: HttpHandler is used for HTTP connection components testing |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef HTTPHANDLER_H |
|
19 #define HTTPHANDLER_H |
|
20 |
|
21 // INCLUDES |
|
22 |
|
23 #include <in_sock.h> |
|
24 #include <http.h> |
|
25 #include <http/mhttpauthenticationcallback.h> |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 const TInt KMaxContentTypeSize = 64; |
|
30 |
|
31 // FORWARD DECLARATIONS |
|
32 class MUINotify; |
|
33 class CHttpEventHandler; |
|
34 class CSettingData; |
|
35 |
|
36 // CLASS DECLARATION |
|
37 |
|
38 |
|
39 /** |
|
40 * CHttpClient |
|
41 * |
|
42 * Class for initiating HTTP transaction. |
|
43 */ |
|
44 class CHttpClient : public CBase, public MHTTPDataSupplier, |
|
45 public MHTTPAuthenticationCallback |
|
46 { |
|
47 public: |
|
48 virtual ~CHttpClient(); |
|
49 static CHttpClient* NewLC(MUINotify& aConsole); |
|
50 static CHttpClient* NewL(MUINotify& aConsole); |
|
51 |
|
52 |
|
53 /** |
|
54 * Start http request |
|
55 */ |
|
56 void InvokeHttpMethodL(const CSettingData* aData, TBool aHasBody, TBool aIsSecure); |
|
57 |
|
58 /** |
|
59 * Set connection info for HTTP FW session |
|
60 */ |
|
61 void SetHttpConnectionInfoL( TBool aUseOwnConnection, |
|
62 RConnection& aConnection, |
|
63 RSocketServ& aSocketServ ); |
|
64 |
|
65 /** |
|
66 * Set throughput calculation on or off. |
|
67 */ |
|
68 void SetPerformance(const TBool aValue); |
|
69 |
|
70 /** |
|
71 * Methods inherited from MHTTPDataSupplier |
|
72 */ |
|
73 virtual TBool GetNextDataPart(TPtrC8& aDataPart); |
|
74 virtual void ReleaseData(); |
|
75 virtual TInt OverallDataSize(); |
|
76 virtual TInt Reset(); |
|
77 |
|
78 /** |
|
79 * Methods inherited from MHTTPAuthenticationCallback |
|
80 */ |
|
81 virtual TBool GetCredentialsL(const TUriC8& aURI, RString aRealm, |
|
82 RStringF aAuthenticationType, |
|
83 RString& aUsername, |
|
84 RString& aPassword); |
|
85 |
|
86 protected: |
|
87 CHttpClient(MUINotify& aConsole); |
|
88 void ConstructL(); |
|
89 private: |
|
90 |
|
91 enum TMenuItems |
|
92 { |
|
93 EGet, |
|
94 EPost, |
|
95 EHead, |
|
96 ETrace, |
|
97 EToggleVerbosity, |
|
98 EQuit |
|
99 }; |
|
100 |
|
101 /** |
|
102 * Display performance information when sending POST. |
|
103 */ |
|
104 void DisplayTimeElapsed(); |
|
105 |
|
106 /** |
|
107 * Set HTTP request header for http fw. |
|
108 */ |
|
109 void SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue); |
|
110 |
|
111 private: |
|
112 RHTTPSession iHttpSession; |
|
113 TTime iLastTimeStamp; |
|
114 TInt iDataChunkCount; |
|
115 RHTTPTransaction iTrans; |
|
116 CHttpEventHandler* iTransObs; |
|
117 HBufC8* iReqBodySubmitBuffer; |
|
118 TPtr8 iReqBodySubmitBufferPtr; |
|
119 TBool iNoMoreDate; |
|
120 MUINotify& iConsole; |
|
121 CSettingData* iSettingData; |
|
122 TBool iDoPerformance; |
|
123 TBuf<KMaxContentTypeSize> iReqBodyContentType; // not used now |
|
124 }; |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 /** |
|
130 * CHttpEventHandler |
|
131 * |
|
132 * Handles all events for the active HTTP transaction. |
|
133 */ |
|
134 class CHttpEventHandler : public CBase, public MHTTPTransactionCallback |
|
135 { |
|
136 public: |
|
137 virtual ~CHttpEventHandler(); |
|
138 static CHttpEventHandler* NewLC(MUINotify& aConsole); |
|
139 static CHttpEventHandler* NewL(MUINotify& aConsole); |
|
140 |
|
141 /** |
|
142 * Turn performance measurement on/off |
|
143 */ |
|
144 void SetPerformance(const TBool aValue){iDoPerformance = aValue;}; |
|
145 |
|
146 /** |
|
147 * Methods from MHTTPTransactionCallback |
|
148 */ |
|
149 virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
150 virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
151 |
|
152 protected: |
|
153 CHttpEventHandler(MUINotify& aConsole); |
|
154 void ConstructL(); |
|
155 private: |
|
156 void DumpRespHeadersL(RHTTPTransaction& aTrans); |
|
157 void DumpRespBody(RHTTPTransaction& aTrans); |
|
158 |
|
159 MHTTPDataSupplier* iRespBody; |
|
160 MUINotify& iConsole; // console for displaying text etc |
|
161 TTime iStartTime; |
|
162 TInt iBodySize; |
|
163 TBool iDoPerformance; |
|
164 }; |
|
165 |
|
166 |
|
167 #endif // HTTPHANDLER_H |
|
168 |