How do I extract custom response headers?

If I want to read the value of something in the html body response, I can do this

    vars['authenticity_token'] = response
        .html()
        .find('meta[name="csrf-token"]')
        .first()
        .attr('content')

But I am trying to find a custom header that we are setting and can’t seem to extract it. I’ve tried variations like this, but nothing seems to work.

    vars['header_token'] = response
        .header()
        .find('custom_header')
        .first()
        .attr('content')

I specifically need these values from a POST response that we are submitting.

Hi @GennyCream

Welcome to the community forum :wave:

Can you try to execute the test with --http-debug="full". This should help identify if the custom_header is in the response, and how you can select it.

You can find example of how to use debugging techniques in k6-learn.

I hope this helps. If you can’t figure it out, share the (sanitized) debug output from the test and we’ll have a look.

Cheers!