MCPcopy Create free account
hub / github.com/axmolengine/axmol / processResponse

Method processResponse

core/network/HttpClient-wasm.cpp:146–241  ·  view source on GitHub ↗

Process Response

Source from the content-addressed store, hash-verified

144
145 // Process Response
146 void HttpClient::processResponse(HttpResponse *response, bool isAlone)
147 {
148 // copy cookie back to document.cookie in case it is changed
149 std::string_view cookieFilename = HttpClient::getInstance()->getCookieFilename();
150 if (!cookieFilename.empty())
151 {
152 EM_ASM_ARGS({
153 try { // suppress cookie file not exist exception at first time
154 document.cookie = FS.readFile(UTF8ToString($0));
155 }catch(e){}
156 }, cookieFilename.data());
157 }
158
159 auto request = response->getHttpRequest();
160 emscripten_fetch_attr_t attr;
161 emscripten_fetch_attr_init(&attr);
162
163 // set http method
164 bool usePostData = false;
165 switch (request->getRequestType())
166 {
167 case HttpRequest::Type::GET:
168 strcpy(attr.requestMethod, "GET");
169 break;
170
171 case HttpRequest::Type::PATCH:
172 strcpy(attr.requestMethod, "PATCH");
173 usePostData = true;
174 break;
175
176 case HttpRequest::Type::POST:
177 strcpy(attr.requestMethod, "POST");
178 usePostData = true;
179 break;
180
181 case HttpRequest::Type::PUT:
182 strcpy(attr.requestMethod, "PUT");
183 usePostData = true;
184 break;
185
186 case HttpRequest::Type::DELETE:
187 strcpy(attr.requestMethod, "DELETE");
188 break;
189
190 default:
191 AXASSERT(false, "HttpClient: unknown request type, only GET, PATCH, POST, PUT or DELETE is supported");
192 break;
193 }
194
195 attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
196
197 auto userData = new (std::nothrow) fetchUserData();
198 userData->isAlone = isAlone;
199 userData->response = response;
200
201 // set header
202 std::vector<std::string> headers;
203 for (std::string_view header : request->getHeaders())

Callers 1

onRequestCompleteMethod · 0.45

Calls 15

getInstanceFunction · 0.85
readFileMethod · 0.80
getHttpRequestMethod · 0.80
getUrlMethod · 0.80
starts_withFunction · 0.50
getCookieFilenameMethod · 0.45
emptyMethod · 0.45
dataMethod · 0.45
findMethod · 0.45
substrMethod · 0.45
push_backMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected