{"action":"created","issue":{"url":"https://api.github.com/repos/webpro/dyson/issues/44","labels_url":"https://api.github.com/repos/webpro/dyson/issues/44/labels{/name}","comments_url":"https://api.github.com/repos/webpro/dyson/issues/44/comments","events_url":"https://api.github.com/repos/webpro/dyson/issues/44/events","html_url":"https://github.com/webpro/dyson/issues/44","id":111712907,"number":44,"title":"Expose request headers to template functions","user":{"login":"rixo","id":1670419,"avatar_url":"https://avatars.githubusercontent.com/u/1670419?v=3","gravatar_id":"","url":"https://api.github.com/users/rixo","html_url":"https://github.com/rixo","followers_url":"https://api.github.com/users/rixo/followers","following_url":"https://api.github.com/users/rixo/following{/other_user}","gists_url":"https://api.github.com/users/rixo/gists{/gist_id}","starred_url":"https://api.github.com/users/rixo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rixo/subscriptions","organizations_url":"https://api.github.com/users/rixo/orgs","repos_url":"https://api.github.com/users/rixo/repos","events_url":"https://api.github.com/users/rixo/events{/privacy}","received_events_url":"https://api.github.com/users/rixo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-15T21:39:29Z","updated_at":"2015-11-07T14:11:53Z","closed_at":null,"body":"Currently template functions receive only params, query, body, and cookies. That would be great to also expose request headers to them. I've got an example use case where I use dyson to back my client e2e tests, and I need to select a response based on Authorization header.\r\n\r\nIn my fork, I've just [added a fifth parameters for the headers](https://github.com/webpro/dyson/compare/master...rixo:expose-headers-to-templates), and it works. Unfortunately, that makes a lot of (potentially unused) arguments, which is not so great... In my opinion, it would be cleaner to expose an object wrapping these 5 arguments, or even the request object itself... even though I see how that could be considered hazardous. Unfortunately, those 2 solutions would be breaking for existing code bases. Maybe as an option? From what I've found, all calls are made in the same file, so that would probably be doable.\r\n\r\nLet me know what you think of the idea, I can work a PR if needed."},"comment":{"url":"https://api.github.com/repos/webpro/dyson/issues/comments/154709171","html_url":"https://github.com/webpro/dyson/issues/44#issuecomment-154709171","issue_url":"https://api.github.com/repos/webpro/dyson/issues/44","id":154709171,"user":{"login":"rixo","id":1670419,"avatar_url":"https://avatars.githubusercontent.com/u/1670419?v=3","gravatar_id":"","url":"https://api.github.com/users/rixo","html_url":"https://github.com/rixo","followers_url":"https://api.github.com/users/rixo/followers","following_url":"https://api.github.com/users/rixo/following{/other_user}","gists_url":"https://api.github.com/users/rixo/gists{/gist_id}","starred_url":"https://api.github.com/users/rixo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rixo/subscriptions","organizations_url":"https://api.github.com/users/rixo/orgs","repos_url":"https://api.github.com/users/rixo/repos","events_url":"https://api.github.com/users/rixo/events{/privacy}","received_events_url":"https://api.github.com/users/rixo/received_events","type":"User","site_admin":false},"created_at":"2015-11-07T14:11:53Z","updated_at":"2015-11-07T14:11:53Z","body":"Hey! No worries.\r\n\r\nI've already worked on this a bit. The approach I've eventually taken is slightly different from what you propose. I indeed added an option `exposeRequest`, that can be global or overridden in each service configuration ; if we let the default be false, then it stays non breaking.\r\n\r\nAlso, I do think that exposing the actual request object is more perennial than trying to wrap it. The latter solution would need future maintenance and I don't think JS developers generally need to be protected against themselves.\r\n\r\nI'll send a PR with that soon. I still need to clean some bits and add some tests."}}