Skip to content

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

Description

@mstoykov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugevaluation neededproposal needs to be validated or tested before fully implementing it in k6help wantednew-httpissues that would require (or benefit from) a new HTTP API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions