Options call fails

Hi all,

k6 Version: k6 v0.36.0 (2022-01-24T09:50:03+0000/ff3f8df, go1.17.6, windows/amd64)

I’m trying to make an options call and it always comes back with a HTTP 405 METHOD_NOT_ALLOWED_ERROR.

As far as I can tell there appears to be some issue with the adding of the headers for an option call

  const urlParams = {
    headers: {
      'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
      'accept-encoding': 'gzip, deflate, br',
      'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
      'Access-Control-Request-Method': 'GET',
      'Access-Control-Request-Headers': 'companyauth',
    },
  };
const optionsResponse = http.options(Url.toString(), urlParams);

OPTIONS /v1/service/mobile/races/nextToGo?jurisdiction=VIC HTTP/1.1
Host: pre-api-backend.beta.company.com.au
User-Agent: k6/0.36.0 (https://k6.io/)
Content-Length: 485
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip

headers=map%5BAccess-Control-Request-Headers%3Acompanycorpauth+Access-Control-Request-Method%3AGET+accept%3Atext%2Fhtml%2Capplication%2Fxhtml%2Bxml%2Capplication%2Fxml%3Bq%3D0.9%2Cimage%2Favif%2Cimage%2Fwebp%2Cimage%2Fapng%2C%2A%2F%2A%3Bq%3D0.8%2Capplication%2Fsigned-exchange%3Bv%3Db3%3Bq%3D0.9+accept-encoding%3Agzip%2C+deflate%2C+br+user-agent%3AMozilla%2F5.0+%28Windows+NT+10.0%3B+Win64%3B+x64%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F96.0.4664.110+Safari%2F537.36%5D  group= iter=0 request_id=ad14c430-3cf5-418e-696f-2a158baae398 scenario=default source=http-debug vu=1
INFO[0001] Response:
HTTP/2.0 405 Method Not Allowed
Content-Length: 80
Allow: GET
Content-Type: application/json
Date: Wed, 01 Jun 2022 02:48:56 GMT
Server: restify

{"error":{"code":"METHOD_NOT_ALLOWED_ERROR","message":"OPTIONS is not allowed"}}  group= iter=0 request_id=ad14c430-3cf5-418e-696f-2a158baae398 scenario=default source=http-debug vu=1

The same header params is passed onto the subsequent GET call and works fine.

any ideas?

Hi @BobRuub,

http.options takes a body as the second argument not a Params which is the third argument. So if you do

const optionsResponse = http.options(Url.toString(), null, urlParams);

it should work.

added, the null into the call and while it fixed the headers still getting an error… :frowning:

  const urlParams = {
    headers: {
      'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
      'accept-encoding': 'gzip, deflate, br',
      'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
      'Access-Control-Request-Method': 'GET',
      'Access-Control-Request-Headers': 'compauth'
    },
  };

  const optionsResponse = http.options(Url.toString(), null, urlParams);
OPTIONS /v1/content-hub-service/mobile/races/nextToGo HTTP/1.1
Host: pre-api-backend.beta.company.com.au
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Access-Control-Request-Headers: compauth
Access-Control-Request-Method: GET

  group= iter=0 request_id=15503288-1b9a-48b8-6d6c-a78a398ab5ae scenario=default source=http-debug vu=1
INFO[0001] Response:
HTTP/2.0 405 Method Not Allowed
Content-Length: 80
Allow: GET
Content-Type: application/json
Date: Thu, 02 Jun 2022 01:22:51 GMT
Server: restify

{"error":{"code":"METHOD_NOT_ALLOWED_ERROR","message":"OPTIONS is not allowed"}}  group= iter=0 request_id=15503288-1b9a-48b8-6d6c-a78a398ab5ae scenario=default source=http-debug vu=1

sorted,

cut down the headers to the following

const headerParamOptions = {
    headers: {
      'Origin': 'https://congo.beta.company.com.au',
      'Connection': 'keep-alive',
      'Access-Control-Request-Method': 'GET',
    },
  };

and it worked fine :slight_smile: