Skip to content
Prev Previous commit
Next Next commit
Add content_type option to headers
  • Loading branch information
coolreader18 committed Feb 18, 2019
commit d7163132831be7231b52115d74bc8110c71ac85b
8 changes: 8 additions & 0 deletions wasm/lib/src/wasm_builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ fn builtin_fetch(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
let method = args.get_optional_kwarg_with_type("method", vm.ctx.str_type(), vm)?;
let headers = args.get_optional_kwarg_with_type("headers", vm.ctx.dict_type(), vm)?;
let body = args.get_optional_kwarg("body");
let content_type = args.get_optional_kwarg_with_type("content_type", vm.ctx.str_type(), vm)?;

let response_format = match response_format {
Some(s) => FetchResponseFormat::from_str(vm, &objstr::get_value(&s))?,
Expand Down Expand Up @@ -176,6 +177,13 @@ fn builtin_fetch(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
}
}

if let Some(content_type) = content_type {
request
.headers()
.set("Content-Type", &objstr::get_value(&content_type))
.map_err(|err| convert::js_py_typeerror(vm, err))?;
}

let window = window();
let request_prom = window.fetch_with_request(&request);

Expand Down