Implement POST and headers

This commit is contained in:
Kovid Goyal 2024-08-16 13:08:28 +05:30
parent 71e8654c80
commit 6d4d11dc9e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 13 additions and 4 deletions

View File

@ -18,6 +18,11 @@
console.log(msg);
}
function base64_to_bytes(base64) {
const bin_string = atob(base64);
return Uint8Array.from(bin_string, (m) => m.codePointAt(0));
}
function notify_that_messages_are_available() {
send_msg({type: 'messages_available', count: messages.length});
}
@ -49,6 +54,14 @@
method: req.method.toUpperCase(),
signal: controller.signal,
};
if (data && data.length > 0) fetch_options.body = base64_to_bytes(data);
if (req.headers) {
const headers = new Headers();
for (const p of req.headers) {
headers.append(p[0], p[1]);
}
fetch_options.headers = headers;
}
const response = await fetch(req.url, fetch_options);
var headers = [];
for (const pair of response.headers) {

View File

@ -250,9 +250,6 @@ class Browser:
class WebEngineBrowser(Browser):
def is_method_ok(self, method: str) -> bool:
return method.upper() in ('GET', 'POST')
def run_worker(self) -> subprocess.Popen:
return run_worker(self.tdir, self.user_agent, self.verify_ssl_certificates, function='webengine_worker')

View File

@ -104,7 +104,6 @@ class Worker(QWebEnginePage):
def start_download(self, output_dir: str, req: Request, data: str) -> DownloadRequest:
filename = os.path.basename(req['filename'])
# TODO: Implement POST requests with data
payload = json.dumps({'req': req, 'data': data})
content = f'''<!DOCTYPE html>
<html><head></head></body><div id="payload">{html.escape(payload)}</div></body></html>