{"action":"opened","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/22367","repository_url":"https://api.github.com/repos/elastic/elasticsearch","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/22367/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/22367/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/22367/events","html_url":"https://github.com/elastic/elasticsearch/issues/22367","id":197985391,"number":22367,"title":"Add ability to set response headers in REST Handlers (ActionPlugin)","user":{"login":"sscarduzio","id":1327189,"avatar_url":"https://avatars.githubusercontent.com/u/1327189?v=3","gravatar_id":"","url":"https://api.github.com/users/sscarduzio","html_url":"https://github.com/sscarduzio","followers_url":"https://api.github.com/users/sscarduzio/followers","following_url":"https://api.github.com/users/sscarduzio/following{/other_user}","gists_url":"https://api.github.com/users/sscarduzio/gists{/gist_id}","starred_url":"https://api.github.com/users/sscarduzio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sscarduzio/subscriptions","organizations_url":"https://api.github.com/users/sscarduzio/orgs","repos_url":"https://api.github.com/users/sscarduzio/repos","events_url":"https://api.github.com/users/sscarduzio/events{/privacy}","received_events_url":"https://api.github.com/users/sscarduzio/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-29T10:25:45Z","updated_at":"2016-12-29T10:25:45Z","closed_at":null,"body":"Hi, I'm writing a plugin and I've been trying to set a cookie.\r\nIt's not easy because albeit I have a RestRequest parameter in `BaseRestHandler.process`, I never have a response object! \r\n\r\nAll I see is just this `channel` (an abstraction over the socket) that is passed around and eventually some internal rest handler will write a serialized response in it. \r\nAnd then it's too late for me to add any response headers.\r\n\r\n## Proposed solution\r\nHow about we let users add response headers from the RestRequest instance?\r\nThe response headers will be later copied over into the response right before being serialized to the channel.\r\n\r\nI.e.\r\n\r\n1. Add a method `RestRequest.setResponseHeader(String name, String value)` which will put an entry into a private`RestRequest.responseHeaderMap` field.\r\n\r\n2. Add a getter method `RestRequest.responseHeaders()` returning the above map.\r\n\r\n2. Modify the `HttpServer.sendResponse` method for copying all the response headers found in `delegate.request().responseHeaders()` into the headers of the response using  the existing`RestResponse.setHeader` method.\r\n\r\n\r\nI could put this in a pull request if I get any feedback that the reasoning is sound for you guys at Elastic."}}
{"actor":{"display_login":"sscarduzio"}}