grafana/k6

Automatically urlencoded request bodies encode null as `<nil>` and objects as `map[...]`

Open

#1185 opened on Oct 4, 2019

View on GitHub
 (3 comments) (1 reaction) (0 assignees)Go (30,564 stars) (1,537 forks)batch import
bugevaluation neededhelp wantednew-http

Description

Based on #1184, the following script:

import http from "k6/http";

export default function () {
    let payload = {
        data: "something",
        another: null ,
    };
    let resp = http.post("https://httpbin.org/post", payload);
    console.log(resp.body);
}

Will produce:

{
  "args": {},
  "data": "",
  "files": {},
  "form": {
    "another": "<nil>",
    "data": "something"
  },
  "headers": {
    "Content-Length": "32",
    "Content-Type": "application/x-www-form-urlencoded",
    "Host": "httpbin.org",
    "User-Agent": "k6/0.26.0-dev (https://k6.io/)"
  },
  "json": null,
  "origin": "46.233.49.37, 46.233.49.37",
  "url": "https://httpbin.org/post"
}

As can be seen by httpbin's response, k6 automagically encodes the object as x-www-form-urlencoded, which is due to this lines https://github.com/loadimpact/k6/blob/1d6fb7f668aa089b374ee8ca35de2a34d77d29ce/js/modules/k6/http/request.go#L148-L151

A quick proposal is to check for null and return "" but I am not certain so we need to read some RFCs, probably or something.

Contributor guide