-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTTPClient.h
111 lines (91 loc) · 3.11 KB
/
HTTPClient.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
============================================================================
Name : HTTPClient.h
Author : artem78
Version : 1.0.2
Copyright :
Description : CHTTPClient declaration
============================================================================
*/
#ifndef HTTPCLIENT_H
#define HTTPCLIENT_H
// INCLUDES
#include <e32std.h>
#include <e32base.h>
#include <http.h>
// FORWARD DECLARATION
class MHTTPClientObserver;
// CLASS DECLARATION
/**
* CHTTPClient - high-level class for making HTTP-requests.
*
* Note: Do not make new request from OnHTTPResponse or OnHTTPError
* callbacks. This will cause panic. (FixMe)
*
*/
class CHTTPClient : public CBase
{
// Constructors and destructor
public:
~CHTTPClient();
static CHTTPClient* NewL(MHTTPClientObserver* aObserver);
static CHTTPClient* NewLC(MHTTPClientObserver* aObserver);
private:
CHTTPClient(MHTTPClientObserver* aObserver);
void ConstructL();
// Custom properties and methods
public:
// ToDo: Add other methods (POST, HEAD, etc...)
void GetL(const TDesC8 &aUrl);
void SetUserAgentL(const TDesC8 &aDes);
void SetHeaderL(TInt aHdrField, const TDesC8 &aHdrValue); // For session
void CancelRequest();
inline TBool IsRequestActive()
{ return iIsRequestActive; };
private:
// Enum
enum THTTPMethod
{
// ToDo: Add other methods (POST, HEAD, etc...)
EGet
};
RHTTPSession iSession;
MHTTPClientObserver* iObserver;
RHTTPTransaction iTransaction;
TBool iIsRequestActive;
void SendRequestL(THTTPMethod aMethod, const TDesC8 &aUrl);
void SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8 &aHdrValue);
void CloseOwnTransaction();
void CloseTransaction(RHTTPTransaction &aTransaction);
TBool IsTransactionOpened(RHTTPTransaction &aTransaction);
// Friends
/*friend void MHTTPClientObserver::MHFRunL(RHTTPTransaction aTransaction,
const THTTPEvent& aEvent);
friend TInt MHTTPClientObserver::MHFRunError(TInt aError, RHTTPTransaction aTransaction,
const THTTPEvent& aEvent);*/
friend class MHTTPClientObserver;
};
class MHTTPClientObserver : public MHTTPTransactionCallback
{
// Inherited from MHTTPTransactionCallback
private:
virtual void MHFRunL(RHTTPTransaction aTransaction,
const THTTPEvent& aEvent);
virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction,
const THTTPEvent& aEvent);
// Custom properties and methods
private:
TInt iLastError;
CHTTPClient* iHTTPClient;
void SetHTTPClient(CHTTPClient *aClient);
public:
virtual void OnHTTPResponseDataChunkRecieved(const RHTTPTransaction aTransaction,
const TDesC8 &aDataChunk, TInt anOverallDataSize, TBool anIsLastChunk) = 0;
virtual void OnHTTPResponse(const RHTTPTransaction aTransaction) = 0;
// @param aError Code of the last error. Equals to 0 if it is HTTP error (ex: 404 Not Found).
virtual void OnHTTPError(TInt aError, const RHTTPTransaction aTransaction) /*= 0*/;
virtual void OnHTTPHeadersRecieved(const RHTTPTransaction aTransaction) = 0;
// Friends
friend class CHTTPClient;
};
#endif // HTTPCLIENT_H