| 266 | return self._raw(url, timeout, options) |
| 267 | |
| 268 | def upload_file(self, url, fpath, timeout=5, options=None): |
| 269 | fname = os.path.basename(fpath) |
| 270 | reqbody = ("%s/nghttp.req.body" % self.TMP_DIR) |
| 271 | with open(fpath, 'rb') as fin: |
| 272 | with open(reqbody, 'wb') as f: |
| 273 | preamble = [ |
| 274 | '--DSAJKcd9876', |
| 275 | 'Content-Disposition: form-data; name="xxx"; filename="xxxxx"', |
| 276 | 'Content-Type: text/plain', |
| 277 | '', |
| 278 | 'testing mod_h2', |
| 279 | '\r\n--DSAJKcd9876', |
| 280 | f'Content-Disposition: form-data; name="file"; filename="{fname}"', |
| 281 | 'Content-Type: application/octet-stream', |
| 282 | 'Content-Transfer-Encoding: binary', |
| 283 | '', '' |
| 284 | ] |
| 285 | f.write('\r\n'.join(preamble).encode('utf-8')) |
| 286 | f.write(fin.read()) |
| 287 | f.write('\r\n'.join([ |
| 288 | '\r\n--DSAJKcd9876', '' |
| 289 | ]).encode('utf-8')) |
| 290 | if not options: |
| 291 | options = [] |
| 292 | options.extend([ |
| 293 | "--data=%s" % reqbody, |
| 294 | "--expect-continue", |
| 295 | "-HContent-Type: multipart/form-data; boundary=DSAJKcd9876"]) |
| 296 | return self._raw(url, timeout, options) |
| 297 | |
| 298 | def _run(self, args) -> ExecResult: |
| 299 | print(("execute: %s" % " ".join(args))) |