Problem with string encoding during redirects

Hello,

During a recent performance test I ran into an issue with redirects: I was getting status code 400’s for a request that was getting redirected once.

To solve the issue, I set maxRedirects to 0 in options, and caught the redirect response manually. Inspecting response.headers.Location, I noticed that the string was not encoded properly (spaces instead of ‘%20’). Sending a subsequent get request to encodeURI(response.headers.Location), I was able to perform the redirect correctly.

Is this expected behaviour?

Best,

Florian

Hmm are you sure this is not a problem with your server? Can you try executing the same request with curl -v and see what happens?

Because running this test script with k6:

import http from 'k6/http';

export let options = {
    maxRedirects: 0,
}

export default function () {
    let resp = http.get('https://httpbin.test.k6.io/redirect-to?url=https://httpbin.test.k6.io/get?foo=param%20with%20a%20space');

    console.log(JSON.stringify(resp, null, 4));
}

you’d get this:

{
    // ...
    "status": 302,
    "status_text": "302 Found",
    "proto": "HTTP/2.0",
    "headers": {
        "Content-Length": "0",
        "Location": "https://httpbin.test.k6.io/get?foo=param%20with%20a%20space",
        "Server": "gunicorn/19.9.0",
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": "true",
        "Date": "Fri, 02 Apr 2021 10:22:21 GMT",
        "Content-Type": "text/html; charset=utf-8"
    },
    // ...
}

The Location header has the proper URL encoding…

1 Like

Hey Ned,

As part of a QA team, indeed I do not rule out a problem with the server.

I’ve verified with curl that the server returns an improperly encoded location in the response headers. Browsers and Postman seem to preemptively fix the encoding issue, whereas k6 and curl do not.

Thank you for your response, I think this answers the issue!