Skip to content

[JENKINS-68154] Custom headers with special characters in their names #309

Description

@jenkins-infra-bot

According to the documentation of the plugin, you can define custom headers for requests with a syntax like this one:

def response = httpRequest customHeaders: [[name: 'foo', value: 'bar']]

The problem arises when you try to use custom headers that use names with non-standard characters. I can't see the way to do something like this:

def response = httpRequest customHeaders: [["my-custom-header-with-hyphen-separator": "${varName}"]]

I know I can do it the hard way:

def headers = new ArrayList()

def headerName1 = 'my-custom-header-with-hyphen-separator'
def varName1 = 'abc'

headers.add(new jenkins.plugins.http_request.util.HttpRequestNameValuePair("${headerName1}","${varName1}"))

However I don't think that's the preferred method as it involves granting certain permissions to scripts.

Under normal circumstances, I would've expected here to use this kind of syntax:

def headers = [ "${headerName1}":"${varName1}","${headerName2}": "${varName2}" ]

Pretty much a json object with one or more key/value pairs.

So, is this possible? is there any alternative syntax that can be used right now to avoid working directly with Java classes?

 


Originally reported by aquesada, imported from: Custom headers with special characters in their names
  • assignee: pratik_0112
  • status: Open
  • priority: Minor
  • component(s): http-request-plugin
  • label(s): configuration, newbie-friendly, plugins
  • resolution: Unresolved
  • votes: 0
  • watchers: 4
  • imported: 20260702-081740
Raw content of original issue

According to the documentation of the plugin, you can define custom headers for requests with a syntax like this one:

def response = httpRequest customHeaders: [[name: 'foo', value: 'bar']]

The problem arises when you try to use custom headers that use names with non-standard characters. I can't see the way to do something like this:

def response = httpRequest customHeaders: [["my-custom-header-with-hyphen-separator": "${varName}"]]

I know I can do it the hard way:

def headers = new ArrayList<jenkins.plugins.http_request.util.HttpRequestNameValuePair>()

def headerName1 = 'my-custom-header-with-hyphen-separator'
def varName1 = 'abc'

headers.add(new jenkins.plugins.http_request.util.HttpRequestNameValuePair("${headerName1}","${varName1}"))

However I don't think that's the preferred method as it involves granting certain permissions to scripts.

Under normal circumstances, I would've expected here to use this kind of syntax:

def headers = [ "${headerName1}":"${varName1}","${headerName2}": "${varName2}" ]

Pretty much a json object with one or more key/value pairs.

So, is this possible? is there any alternative syntax that can be used right now to avoid working directly with Java classes?

 

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for Enhancement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions