K6 returns status as 0 when response header misses location on a 303 response

I have an api that returns 303 response but without a Location header in the response.

The same request works fine from postman even though the response lacks the Location header.

In K6, i get a warning

Request Failed error=“Put “endpoint”: 303 response missing Location header”

and a http-debug=full shows that the request has failed and the response is 0 with

“error”:“303 response missing Location header”,“error_code”:1000,

Have tried to set redirets to 0, even that does not help.

Is there any way to make the request go through even though the response header lacks a location ?

Hi,

I wasn’t familiar with the 303 See Other status code, but according to RFC 7231 it reads to me like the Location header “SHOULD” be specified by the server, just as with the other redirect codes, even though that’s not explicitly stated. If it’s missing then I don’t see the point of the server responding with “See Other”… :slight_smile:

I’m curious what the behavior of Postman is in this case. Does it just drop the request at that point?

While the k6 HTTP client will follow redirects by default, you can set maxRedirects: 0 to disable this behavior and do all requests manually. Ah, I missed that you already tried this. That should work in this case… :confused:

If that fails or you need more complex behavior, you can always write your own implementation in Go and expose it as a JavaScript extension.

1 Like

@imiric is correct - a 303 should most definitely respond with a Location header.

I think the warning is actually a bit misleading: the request is still made successfully (otherwise we couldn’t tell that there was no Location header) so you’ll just have to ignore the warning until the server is fixed/updated.

If you want to suppress the warning entirely, you can specify in options that warnings should throw an exception:

export const options = {
  throw: true,
};

That would then allow you to try/catch it and do what you want with the message:

let res;

try {
  res = http.get("https://localhost:44366/303");
}
catch (err) {
  console.log('caught error: ' + err);
}
1 Like