Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-68154

Custom headers with special characters in their names

XMLWordPrintable

      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?

       

            janario Janario Oliveira
            aquesada Alfredo Quesada
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: