* Creates the XHR object and sends the request. * * @private
()
| 141 | * @private |
| 142 | */ |
| 143 | private _create() { |
| 144 | const opts = pick( |
| 145 | this._opts, |
| 146 | "agent", |
| 147 | "pfx", |
| 148 | "key", |
| 149 | "passphrase", |
| 150 | "cert", |
| 151 | "ca", |
| 152 | "ciphers", |
| 153 | "rejectUnauthorized", |
| 154 | "autoUnref", |
| 155 | ); |
| 156 | opts.xdomain = !!this._opts.xd; |
| 157 | |
| 158 | const xhr = (this._xhr = this.createRequest(opts)); |
| 159 | |
| 160 | try { |
| 161 | debug("xhr open %s: %s", this._method, this._uri); |
| 162 | xhr.open(this._method, this._uri, true); |
| 163 | try { |
| 164 | if (this._opts.extraHeaders) { |
| 165 | // @ts-ignore |
| 166 | xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true); |
| 167 | for (let i in this._opts.extraHeaders) { |
| 168 | if (this._opts.extraHeaders.hasOwnProperty(i)) { |
| 169 | xhr.setRequestHeader(i, this._opts.extraHeaders[i]); |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | } catch (e) {} |
| 174 | |
| 175 | if ("POST" === this._method) { |
| 176 | try { |
| 177 | xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8"); |
| 178 | } catch (e) {} |
| 179 | } |
| 180 | |
| 181 | try { |
| 182 | xhr.setRequestHeader("Accept", "*/*"); |
| 183 | } catch (e) {} |
| 184 | |
| 185 | this._opts.cookieJar?.addCookies(xhr); |
| 186 | |
| 187 | // ie6 check |
| 188 | if ("withCredentials" in xhr) { |
| 189 | xhr.withCredentials = this._opts.withCredentials; |
| 190 | } |
| 191 | |
| 192 | if (this._opts.requestTimeout) { |
| 193 | xhr.timeout = this._opts.requestTimeout; |
| 194 | } |
| 195 | |
| 196 | xhr.onreadystatechange = () => { |
| 197 | if (xhr.readyState === 3) { |
| 198 | this._opts.cookieJar?.parseCookies( |
| 199 | // @ts-ignore |
| 200 | xhr.getResponseHeader("set-cookie"), |
no test coverage detected