Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Setting custom Http headers with HandleHttpResponse

avatar
New Contributor

I have a flow that starts with an HandleHttpRequest and passes through a custom processor then ends with a HandleHttpResponse to manage a web request. I need to set some custom HTTP headers in the response based on flowfile attributes available to the HandleHttpResponse processor. I can't for the life of me figure out how to get them set although google searches keep givng me the impression that its possible with dynamic properties, but I can't find any examples. The flow is working and I'm able to see attributes I set, and the flow file contents are received back on the browser. However I would prefer to set some headers in the response instead of capturing the data in the browser and setting the headers there.

Can anyone help me out with some pointers on what to try

1 ACCEPTED SOLUTION

avatar

Hello @John Preston

Yes, it's possible to pass custom HTT headers from HandleHttpResponse via dynamic properties. At HandleHttpResponse processor configuration tab, you can add a dynamic property by clicking the 'plus' sign, then enter its name which will be a name of the custom HTTP header, and specify a NiFi Attribute Expression Language (EL) as its value. You can find more about EL here NiFi Expression Language Guide.

13262-handlehttpresponse.png

Test sending a HTTP request via cURL command:

$ curl -i localhost:8081
HTTP/1.1 200 OK
Date: Sun, 05 Mar 2017 23:26:00 GMT
NiFi FileName: 100866877045484
Transfer-Encoding: chunked
Server: Jetty(9.3.9.v20160517)
{"Result": "OK"}

Thanks,

Koji

View solution in original post

3 REPLIES 3

avatar

Hello @John Preston

Yes, it's possible to pass custom HTT headers from HandleHttpResponse via dynamic properties. At HandleHttpResponse processor configuration tab, you can add a dynamic property by clicking the 'plus' sign, then enter its name which will be a name of the custom HTTP header, and specify a NiFi Attribute Expression Language (EL) as its value. You can find more about EL here NiFi Expression Language Guide.

13262-handlehttpresponse.png

Test sending a HTTP request via cURL command:

$ curl -i localhost:8081
HTTP/1.1 200 OK
Date: Sun, 05 Mar 2017 23:26:00 GMT
NiFi FileName: 100866877045484
Transfer-Encoding: chunked
Server: Jetty(9.3.9.v20160517)
{"Result": "OK"}

Thanks,

Koji

avatar
New Contributor

Thanks for the answer. I was missing the add property button because I was always viewing the HandleHttpResponse processor configuration while the processor was active, and in that mode the add property button (+) wasn't shown. Once I stopped the processor and selected the configuration option, I saw the add property (+) button which was what I was missing and couldn't figure out how to access. Its working now. Thanks.

avatar

Glad to hear you figured it out. Thanks!