Skip to content

Commit

Permalink
fix buffer body copy
Browse files Browse the repository at this point in the history
  • Loading branch information
1Conan committed Apr 29, 2023
1 parent 4a5fd30 commit ad35f63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ export class Client {
if (args.cookieJar) {
const cookie = args.cookieJar.getCookieStringSync(url)

options.headers = { ...args.headers, Cookie: cookie }
options.headers = { ...options.headers, Cookie: cookie }
}

if (args.body?.constructor.name === 'FormData') {
options.headers = (<FormData> args.body).getHeaders(args.headers)
options.headers = (args.body as FormData).getHeaders(options.headers)

options.body = (<FormData> args.body).getBuffer()
options.body = (args.body as FormData).getBuffer()
}

const res: Response<T> = await requestPromise.call(this.#client, url, options)
Expand Down
9 changes: 7 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,13 @@ impl Client {
DataType::Binary(v) if v.is_some() => {
let val = v.unwrap();

let mut buf= JsBuffer::new(cx, val.len())?;
buf.as_mut_slice(cx).copy_from_slice(&val);
let mut buf= JsBuffer::new(cx, val.len()).unwrap();

let lock = cx.lock();
match buf.try_borrow_mut(&lock) {
Ok(mut dest) => dest.copy_from_slice(&val),
Err(error) => log::error!("Error while copying buffer: {:?}", error)
}

obj.set(cx, "body", buf)?;
}
Expand Down

0 comments on commit ad35f63

Please sign in to comment.