jenkinsci / jenkinsci/http-request-plugin

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

Open
#309 5 comments 0 reactions 0 assignees View on GitHub
component:http-request-plugin good first issue imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
176
Forks
158
Avg merge
1d 16h
Merged PRs (30d)
3

Description

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?

 

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.