Process Response
| 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()) |
no test coverage detected