|
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-8C5A65E6-D753-472F-B885-FD0409589036" xml:lang="en"><title>HTTP |
|
13 Whole Message Filter Example</title><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <p>The following diagram illustrates the class relationship between the <codeph>MHTTPDataOptimiser</codeph> interface |
|
15 and the <codeph>RHTTPSession</codeph> class: </p> |
|
16 <fig id="GUID-25859A19-F3C8-5FBD-B491-C58E5C973424"> |
|
17 <title> Class relationship between MHTTPDataOptimiser and |
|
18 RHTTPSession </title> |
|
19 <image href="GUID-9DCAB1DC-D085-576C-A0B9-713E3BF2CAD5_d0e186197_href.png" placement="inline"/> |
|
20 </fig> |
|
21 <p>For more information about <xref href="GUID-F34F7481-00CF-3A1B-8D45-D053AD6769A8.dita"><apiname>MHTTPTransactionCallback</apiname></xref>, |
|
22 see <xref href="GUID-1D32D093-1B7B-5CE8-B57D-5469C1E8E4B9.dita">A simple HTTP Client |
|
23 session</xref>. </p> |
|
24 <p>The following code segment illustrates how to define the header file required |
|
25 for implementing the HTTP Whole Message Filter APIs: </p> |
|
26 <codeblock id="GUID-1D7FA528-68D6-5AEE-B9F3-CBACC03855AB" xml:space="preserve">#include <http.h> |
|
27 |
|
28 class CMyHTTPClient: public CBase, |
|
29 public MHTTPTransactionCallback, |
|
30 public MHttpDataOptimiser |
|
31 { |
|
32 public: // methods from MHTTPTransactionCallback |
|
33 virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
34 virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent); |
|
35 |
|
36 public: // methods from MHttpDataOptimiser |
|
37 virtual void EncodeL (const TDesC8& aHttpData, HBufC8*& aEncodedData); |
|
38 virtual void DecodeL (const TDesC8& aData, HBufC8*& aHttpData, TBool& aTransFail); |
|
39 };</codeblock> |
|
40 <p>The following code segment illustrates how HTTP Whole Message Filter APIs |
|
41 can be used to enable support for Web Acceleration: </p> |
|
42 <codeblock id="GUID-2F062305-2D15-534C-8239-FAE4002DB79E" xml:space="preserve">#include "CMyHTTPClient.h" |
|
43 |
|
44 // CMyHTTPClient.cpp |
|
45 // |
|
46 // defines CMyHTTPClient class: CMyHTTPClient |
|
47 // Literals used in the file |
|
48 _LIT8(KHttpAuthenticationUrl, "http://remix.kwed.org"); |
|
49 |
|
50 |
|
51 void CMyHTTPClient::CreateTransactionL() |
|
52 { |
|
53 TUriParser8 up; |
|
54 up.Parse(KHttpAuthenticationUrl); |
|
55 |
|
56 RHTTPSession session; |
|
57 RHTTPTransaction trans; |
|
58 |
|
59 // Open the HTTP session |
|
60 session.OpenL(); |
|
61 CleanupClosePushL(session); |
|
62 |
|
63 RStringPool strP = session.StringPool(); |
|
64 |
|
65 //To enable MHTTPDataOptimiser for transaction |
|
66 |
|
67 // Open a GET transaction, specifying this object as the request body data supplier |
|
68 trans = session.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
69 CleanupClosePushL(trans); |
|
70 trans.SetupHttpDataOptimiser(*this); |
|
71 |
|
72 trans.SubmitL(); |
|
73 CleanupStack::PopAndDestroy(&trans); |
|
74 CActiveScheduler::Start(); |
|
75 |
|
76 CleanupStack::PopAndDestroy(&session); //Closes the session |
|
77 |
|
78 } |
|
79 |
|
80 TInt CMyHTTPClient::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent) |
|
81 { |
|
82 // Handle Error appropriately |
|
83 } |
|
84 |
|
85 void CMyHTTPClient::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) |
|
86 { |
|
87 // Handle events from the framework. |
|
88 switch (aEvent.iStatus) |
|
89 { |
|
90 case KErrHttpOptimiserFailsTrans: |
|
91 { |
|
92 INFO_PRINTF1(_L("Cancelling/Failing Transaction\n")); |
|
93 aTransaction.Fail(THTTPFilterHandle::EProtocolHandler); |
|
94 } break; |
|
95 |
|
96 } |
|
97 return; |
|
98 //The following statement is used to eliminate leavescan errors |
|
99 User::Leave(KErrGeneral); |
|
100 } |
|
101 |
|
102 void CMyHTTPClient::EncodeL (const TDesC8& aHttpData, HBufC8* &aEncodedData) |
|
103 { |
|
104 //Provide your own custom encoding implementation |
|
105 } |
|
106 |
|
107 void CMyHTTPClient::DecodeL (const TDesC8& aData, HBufC8*& aHttpData, TBool& aTransFail) |
|
108 { |
|
109 //Provide your own custom decoding implementation |
|
110 }</codeblock> |
|
111 <p>This code enables the <codeph>MHTTPDataOptimiser</codeph> for a transaction |
|
112 by using <codeph>RHTTPTransaction::SetupHTTPDataOptimiser()</codeph> and also |
|
113 illustrates where custom encoding and decoding mechanisms are implemented. </p> |
|
114 <p> <b>Note:</b> Alternatively, in this code, you can use the following code |
|
115 segment to enable <codeph>MHTTPDataOptimiser</codeph> for a particular session. </p> |
|
116 <p> <codeph>session.SetupHttpDataOptimiser(*this); </codeph> </p> |
|
117 </conbody></concept> |