{"record":{"id":"1444fcfae28c5e9b","repo":"karatelabs/karate","slug":"missing-argument-for-header-httpresponse","errorCode":null,"errorMessage":"missing argument for header()","messagePattern":"missing argument for header\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/HttpResponse.java","lineNumber":389,"sourceCode":"    }\n\n    /**\n     * Returns true if this response represents a skipped request.\n     * A request is skipped when a listener returns false from HTTP_ENTER event.\n     */\n    public boolean isSkipped() {\n        return status == 0;\n    }\n\n    /**\n     * 1-arg form: {@code response.header('X')} — returns the last value (String) or null.\n     * 2-arg form: {@code response.header('X', 'v')} — sets the header. {@code null}\n     * value removes the header. {@code List} value sets all values.\n     */\n    private JavaInvokable header() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"missing argument for header()\");\n            }\n            String name = args[0] + \"\";\n            if (args.length == 1) {\n                return getHeader(name);\n            }\n            putHeaderValue(name, args[1]);\n            return null;\n        };\n    }\n\n    private JavaInvokable headerValues() {\n        return args -> {\n            if (args.length > 0) {\n                return getHeaderValues(args[0] + \"\");\n            } else {\n                throw new RuntimeException(\"missing argument for headerValues()\");\n            }\n        };","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/HttpResponse.java#L371-L407","documentation":"response.header() is a JS invokable: the 1-arg form gets a header value, the 2-arg form sets it. Calling it with no arguments is ambiguous and unsupported, so the library throws before dereferencing args[0].","triggerScenarios":"`response.header()` with zero arguments from JS member access, e.g. `response.header()` intending to read all headers, or a computed name variable that is undefined.","commonSituations":"Trying to enumerate headers (use the member/map access instead); a typo where the header name argument was dropped during refactoring.","solutions":["Pass the header name: `response.header('Content-Type')` to read.","Pass name and value to set: `response.header('X-Custom', 'v')`; pass null as value to remove.","To list all headers, access the headers collection/map on the response object instead of header().","Guard computed names: `if (name != null) response.header(name, value)`.­"],"exampleFix":"// before\nresponse.header()\n// after\nvar ct = response.header('Content-Type')","handlingStrategy":"validation","validationCode":"if (name != null) response.header(name, value);","typeGuard":"function headerNeedsValue(args) { return args.length >= 1; }","tryCatchPattern":"try { return response.header(name); } catch (e) { if (('' + e).includes('missing argument')) return null; throw e; }","preventionTips":["Always pass at least the header name","Use response.header(name) to read, response.header(name, value) to set, value=null to remove","For enumerating all headers use the headers map, not header()"],"tags":["http","response","headers"],"backgroundTag":"missing-required-argument","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}