ZFFramework
 
Loading...
Searching...
No Matches
ZFHttpRequest.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFHttpRequest_h_
7#define _ZFI_ZFHttpRequest_h_
8
9#include "ZFNetDef.h"
11
20 ZFENUM_VALUE(DELETE)
21 ZFENUM_VALUE(CONNECT)
22 ZFENUM_VALUE(OPTIONS)
37
38zfclassFwd _ZFP_ZFHttpRequestPrivate;
39// ============================================================
43zfclass ZFLIB_ZFNet ZFHttpResponse : zfextend ZFObject {
44 ZFOBJECT_DECLARE(ZFHttpResponse, ZFObject)
45 ZFOBJECT_PRIVATE_ALLOC("can only be created by ZFHttpRequest")
46
47
60
61 // ============================================================
64 , ZFMP_IN(const zfstring &, key)
65 )
66
69
74 , ZFMP_IN(const zfiter &, it)
75 )
78 , ZFMP_IN(const zfiter &, it)
79 )
80
81 // ============================================================
86
87protected:
89 virtual void objectOnInit(void);
91 virtual void objectOnDealloc(void);
92protected:
95
96private:
97 _ZFP_ZFHttpRequestPrivate *d;
98 friend zfclassFwd ZFHttpRequest;
99 friend zfclassFwd _ZFP_ZFHttpRequestPrivate;
100};
101
102// ============================================================
121zfclass ZFLIB_ZFNet ZFHttpRequest : zfextend ZFObject, zfimplement ZFTaskId {
122 ZFOBJECT_DECLARE(ZFHttpRequest, ZFObject)
123 ZFIMPLEMENT_DECLARE(ZFTaskId)
124
125
131 ZFEVENT(OnRequestPrepare)
138 ZFEVENT(OnRequest)
139
148 ZFEVENT(OnResponsePrepare)
157 ZFEVENT(OnResponse)
158
163 ZFMP_IN(const zfstring &, url)
164 , ZFMP_IN_OPT(ZFHttpMethod, method, v_ZFHttpMethod::e_GET)
166
169
173
177
180
181 // ============================================================
189 , ZFMP_IN(const zfstring &, key)
190 , ZFMP_IN(const zfstring &, value)
194 , ZFMP_IN(const zfstring &, key)
198 , ZFMP_IN(const zfstring &, key)
200
203
208 , ZFMP_IN(const zfiter &, it)
212 , ZFMP_IN(const zfiter &, it)
216 , ZFMP_IN_OUT(zfiter &, it)
217 , ZFMP_IN(const zfstring &, value)
221 , ZFMP_IN_OUT(zfiter &, it)
223
224 // ============================================================
227 , ZFMP_IN(const zfstring &, buf)
231 , ZFMP_IN(const void *, buf)
232 , ZFMP_IN(zfindex, count)
234
241
242 // ============================================================
252 , ZFMP_IN_OPT(const ZFListener &, callback, zfnull)
254
257
262
267
268protected:
270 virtual void objectOnInit(void);
272 virtual void objectOnDealloc(void);
273protected:
276
277private:
278 _ZFP_ZFHttpRequestPrivate *d;
279public:
280 void _ZFP_ZFHttpRequest_notifyResponse(ZF_IN ZFHttpResponse *response);
281};
282
283// ============================================================
286 , ZFMP_IN(const zfchar *, src)
290 , ZFMP_IN_OUT(zfstring &, ret)
291 , ZFMP_IN(const zfchar *, src)
293
296 , ZFMP_IN(const zfchar *, src)
300 , ZFMP_IN_OUT(zfstring &, ret)
301 , ZFMP_IN(const zfchar *, src)
303
306 , ZFMP_IN(const zfchar *, url)
307 , ZFMP_IN(const ZFJson &, params)
311 , ZFMP_IN_OUT(zfstring &, url)
312 , ZFMP_IN(const ZFJson &, params)
316 , ZFMP_IN_OUT(zfstring &, url)
317 , ZFMP_IN(const zfchar *, key)
318 , ZFMP_IN(const zfchar *, value)
322 , ZFMP_IN(const zfchar *, url)
323 , ZFMP_IN(const zfchar *, key)
324 , ZFMP_IN_OPT(const zfchar *, def, zfnull)
326
327// ============================================================
334 , ZFMP_IN(const zfstring &, url)
340 , ZFMP_IN(const zfstring &, url)
346
348#endif // #ifndef _ZFI_ZFHttpRequest_h_
349
_ZFT_t_zfchar zfchar
char wrapper
Definition ZFCoreTypeDef_CharType.h:17
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
_ZFT_t_zfint zfint
same as int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:165
_zft_zftimet zftimet
time unit, ensured at least 64 bit, ensured signed
Definition ZFCoreTypeDef_CoreType.h:203
#define zftimetInvalid()
invalid time value
Definition ZFCoreTypeDef_CoreType.h:205
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZFENUM_SEPARATOR()
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:158
#define ZFENUM_VALUE_REGISTER(Value)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:168
#define ZFENUM_REG(ZFLIB_, EnumName,...)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:186
#define ZFENUM_VALUE(Value)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:151
#define ZFENUM_BEGIN(ZFLIB_, EnumName)
macros to define reflectable enum type
Definition ZFEnumDeclare.h:147
#define ZFENUM_END(ZFLIB_, EnumName)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:172
void ZFUrlParamSet(zfstring &url, const ZFJson &params)
util to modify url
zfstring ZFUrlParamGet(const zfchar *url, const zfchar *key, const zfchar *def=(zft_zfnull))
util to get param from url
zfautoT< ZFHttpResponse > ZFHttpHeadCache(const zfstring &url)
util to fetch head info, or load from cache if available
zfautoT< ZFHttpResponse > ZFHttpHeadCacheRemove(const zfstring &url)
see ZFHttpHeadCache
v_ZFHttpMethod::ZFEnumType ZFHttpMethod
see v_ZFHttpMethod
Definition ZFHttpRequest.h:35
zfstring ZFUrlEncode(const zfchar *src)
url encode util
zfstring ZFUrlDecode(const zfchar *src)
url decode util
void ZFUrlDecodeT(zfstring &ret, const zfchar *src)
url decode util
void ZFUrlEncodeT(zfstring &ret, const zfchar *src)
url encode util
zfstring ZFUrlForParam(const zfchar *url, const ZFJson &params)
util to generate url
void ZFHttpHeadCacheRemoveAll()
see ZFHttpHeadCache
#define ZFMP_IN_OUT(ParamType, paramName)
see ZFMP_IN
Definition ZFMethod.h:117
#define ZFMP_IN_OPT(ParamType, paramName, DefaultValue)
see ZFMP_IN
Definition ZFMethod.h:108
#define ZFMP_IN(ParamType, paramName)
macro to wrap param types for ZFMETHOD_INLINE_0 series
Definition ZFMethod.h:105
#define ZFMETHOD_DECLARE_0(ReturnType, MethodName)
see ZFMethod
Definition ZFMethodDeclare.h:693
#define ZFMETHOD_DECLARE_STATIC_0(ReturnType, MethodName)
see ZFMethod
Definition ZFMethodDeclare.h:708
#define ZFMETHOD_DECLARE_2(ReturnType, MethodName, ZFMP_0, ZFMP_1)
see ZFMethod
Definition ZFMethodDeclare.h:1025
#define ZFMETHOD_DECLARE_1(ReturnType, MethodName, ZFMP_0)
see ZFMethod
Definition ZFMethodDeclare.h:854
#define ZFMETHOD_FUNC_DECLARE_2(ZFLIB_, ReturnType, MethodName, ZFMP_0, ZFMP_1)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:763
#define ZFMETHOD_FUNC_DECLARE_3(ZFLIB_, ReturnType, MethodName, ZFMP_0, ZFMP_1, ZFMP_2)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:910
#define ZFMETHOD_FUNC_DECLARE_0(ZFLIB_, ReturnType, MethodName)
declare function type of ZFMethod
Definition ZFMethodFuncDeclare.h:493
#define ZFMETHOD_FUNC_DECLARE_1(ZFLIB_, ReturnType, MethodName, ZFMP_0)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:624
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
global header for ZFNet module
#define ZFLIB_ZFNet
used to export symbols
Definition ZFNetDef.h:15
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38
#define ZFOBJECT_ON_INIT_DECLARE_2(ZFMP_0, ZFMP_1)
see ZFOBJECT_ON_INIT_INLINE_1
Definition ZFObjectDeclare.h:290
#define ZFOBJECT_DECLARE(ChildClass, SuperClass,...)
necessary for every class inherit from ZFObject
Definition ZFObjectDeclare.h:126
#define ZFOBJECT_PRIVATE_ALLOC(...)
mark this object can not be allocated directly
Definition ZFObjectDeclare.h:245
#define ZFIMPLEMENT_DECLARE(ImplementedInterfaces,...)
see ZFINTERFACE_DECLARE
Definition ZFObjectInterface.h:169
#define zfimplement
shows class implement from interface, see ZFInterface
Definition ZFObjectInterface.h:24
#define ZFEVENT(YourEvent)
see ZFObject::observerNotify
Definition ZFObjectObserver.h:328
#define ZFPROPERTY_ASSIGN(Type, Name,...)
see ZFPROPERTY_RETAIN
Definition ZFPropertyDeclare.h:128
#define ZFPROPERTY_ON_ATTACH_DECLARE(Type, Name)
see ZFPROPERTY_ON_INIT_DECLARE
Definition ZFPropertyDeclare.h:248
virtual zftimet & timeout()
timeout
Definition ZFHttpRequest.h:168
virtual zfiter headerIter()
iterator for header
virtual void objectOnDealloc(void)
override this to destroy your object
virtual void objectInfoImplAppend(zfstring &ret)
see objectInfo
virtual void headerIterRemove(zfiter &it)
iterator for header
virtual zfstring headerInfo()
print all header info, usually for debug use only
virtual zfstring headerIterKey(const zfiter &it)
iterator for header
virtual zfstring headerIterValue(const zfiter &it)
iterator for header
virtual void objectOnInit(const zfstring &url, ZFHttpMethod method=(v_ZFHttpMethod::e_GET))
init and connect
virtual void headerRemove(const zfstring &key)
remove http header
virtual void stop()
cancel the request
static zfbool httpsAvailable()
whether https impl available
virtual zfautoT< ZFHttpResponse > startSync(zftimet timeout=(((zftimet) -1)))
util to perform sync request, return null if timeout
virtual zfstring contentInfo()
print all content info, usually for debug use only
virtual void body(const zfstring &buf)
append content to body
virtual void header(const zfstring &key, const zfstring &value)
set http header
virtual ZFHttpMethod & httpMethod()
the http method, GET/POST/..., GET by default
Definition ZFHttpRequest.h:175
virtual zfstring & url()
the request url
Definition ZFHttpRequest.h:171
virtual zfindex headerCount()
response header count
virtual void start(const ZFListener &callback=(zft_zfnull))
start the request
see ZFHttpRequest
Definition ZFHttpRequest.h:43
virtual void objectOnInit(void)
override this to init your object
virtual void objectOnDealloc(void)
override this to destroy your object
virtual zfiter headerIter()
iterator for header
virtual zfstring headerIterKey(const zfiter &it)
iterator for header
virtual zfbool & success()
whether the request is considered success
Definition ZFHttpRequest.h:48
virtual void objectInfoImplAppend(zfstring &ret)
see objectInfo
virtual zfstring header(const zfstring &key)
get the response header
virtual zfstring & errorHint()
error hint, if error occurred
Definition ZFHttpRequest.h:52
virtual zfindex headerCount()
response header count
virtual zfstring headerInfo()
print all header info, usually for debug use only
virtual zfint & code()
http response code
Definition ZFHttpRequest.h:50
virtual zfstring & body()
response body
Definition ZFHttpRequest.h:59
virtual zfstring contentInfo()
print all content info, usually for debug use only
virtual zfstring headerIterValue(const zfiter &it)
iterator for header
JSON item.
Definition ZFJson.h:167
listener as ZFCallback, mostly used by ZFObject::observerNotify
Definition ZFObjectObserver.h:30
http method type
Definition ZFHttpRequest.h:15
type restrict version of zfauto
Definition zfautoFwd.h:110
iterator for ZFFramework
Definition zfiter.h:40