Skylicht Engine
Loading...
Searching...
No Matches
CHttpRequest.h
1/*
2!@
3MIT License
4
5Copyright (c) 2021 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "pch.h"
28
29#ifndef __EMSCRIPTEN__
30
31#include "IHttpRequest.h"
32
33#include "curl/curl.h"
34#include "CHttpStream.h"
35
36// 100kb buffer download
37#define DOWNLOADBUFFER_SIZE 102400
38
39namespace Skylicht
40{
41 namespace Network
42 {
43 class CHttpRequest : public IHttpRequest
44 {
45 protected:
46 // curl handle
47 CURL* m_curl;
48 CURLM* m_multiHandle;
49
50 void* m_formpost;
51 void* m_lastptr;
52
53 int m_needContinue;
54
55 bool m_sendRequest;
56
57 bool m_cancel;
58 bool m_isTimeOut;
59
60 unsigned char* m_downloadBuffer;
61 unsigned long m_sizeBuffer;
62
63 unsigned long m_requestTime;
64 unsigned long m_time;
65 unsigned long m_revcTime;
66 unsigned long m_currentTime;
67 unsigned long m_requestTimeOut;
68
69 unsigned long m_totalBytePerSecond;
70 unsigned long m_bytePerSecond;
71
72 std::string m_postField;
73 std::string m_sessionFile;
74
75 curl_slist* m_headerlist;
76
77 bool m_checkTimeout;
78
79 public:
80 CHttpRequest(IHttpStream* stream);
81
82 virtual ~CHttpRequest();
83
84 static void globalInit();
85
86 static void globalFree();
87
88 static std::string urlEncode(const std::string& s);
89
90 inline void setSessionFile(const char* session)
91 {
92 m_sessionFile = session;
93 }
94
95 void sendRequestByPost();
96 void sendRequestByPostJson();
97 void sendRequestByGet();
98 void sendRequestByPut();
99 void sendRequestByDelete();
100
101 virtual void sendRequest();
102
103 virtual bool updateRequest();
104
105 inline bool isSendRequest()
106 {
107 return m_sendRequest;
108 }
109
110 bool checkTimeOut();
111
112 virtual bool isTimeOut()
113 {
114 return m_isTimeOut;
115 }
116
117 inline unsigned long getRequestTime()
118 {
119 return m_currentTime - m_requestTime;
120 }
121
122 void onRevcData(unsigned char* lpData, unsigned long size, unsigned long num);
123
124 void onReadData(unsigned char* lpData, unsigned long size, unsigned long num);
125
126 virtual unsigned long getSpeedDownload()
127 {
128 return m_bytePerSecond;
129 }
130
131 virtual void cancel()
132 {
133 m_cancel = true;
134 }
135
136 virtual bool isCancel()
137 {
138 return m_cancel;
139 }
140
141 inline long getCurrentTimeOut()
142 {
143 return m_currentTime - m_revcTime;
144 }
145
146 inline long getTimeOut()
147 {
148 return m_requestTimeOut;
149 }
150 };
151 }
152}
153
154#endif
Definition IHttpStream.h:32
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29