Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arbitrary binary HTTP request bodies #874

Closed
na-- opened this issue Dec 17, 2018 · 1 comment
Closed

Arbitrary binary HTTP request bodies #874

na-- opened this issue Dec 17, 2018 · 1 comment

Comments

@na--
Copy link
Member

na-- commented Dec 17, 2018

Currently users can read a binary file or receive a binary HTTP response and send that as an HTTP request body:

import { sleep } from "k6";
import http from "k6/http";
import crypto from "k6/crypto";

// Manually downloaded from https://httpbin.org/image/png
var binaryFile = open("./image.png", "b");

export default function (data) {
    let binaryResp = http.get("https://httpbin.org/image/png", { responseType: "binary" });

    console.log(crypto.sha256(binaryFile, "hex"));
    console.log(crypto.sha256(binaryResp.body, "hex"));
    console.log("Lengths: ", binaryFile.length, binaryResp.body.length);

    let resp = http.post("https://httpbin.org/anything", binaryResp.body);
    console.log(resp.body);
}

They can even modify those binary arrays without extending them (so binaryFile[100] = 123; will work, but binaryFile[10000] = 123; won't). But they cannot construct a new binary buffer from scratch. Normal JS arrays won't (and probably shouldn't) work, and JS strings are unsuitable for a lot of tasks, since they're UTF-16 encoded. Ideally, once we fix this issue, we can use typed arrays for sending arbitrary binary payloads as HTTP request bodies.

@na--
Copy link
Member Author

na-- commented Jan 26, 2021

This was fixed by #1776, which allowed users to pass ArrayBuffer values as the request body. Everything else that's binary-related is tracked by #1020 and has a WIP PR already (#1800).

@na-- na-- closed this as completed Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant