{"action":"created","comment":{"url":"https://api.github.com/repos/3scale/apicast/pulls/comments/153214697","pull_request_review_id":79188039,"id":153214697,"diff_hunk":"@@ -0,0 +1,129 @@\n+--- Headers policy\n+-- This policy allows to include custom headers that will be sent to the\n+-- upstream as well as modify or delete the ones included in the original\n+-- request.\n+-- Similarly, this policy also allows to add, modify, and delete the headers\n+-- included in the response.\n+\n+local ipairs = ipairs\n+local type = type\n+local insert = table.insert\n+\n+local policy = require('apicast.policy')\n+local _M = policy.new('Headers policy')\n+\n+local new = _M.new\n+\n+local function new_header_value(current_value, value_to_add)\n+  local new_value = current_value or {}\n+\n+  if type(new_value) == 'string' then\n+    new_value = { new_value }\n+  end\n+\n+  insert(new_value, value_to_add)\n+  return new_value\n+end\n+\n+local function add_request_header(header, value, req_headers)\n+  local new_value = new_header_value(req_headers[header], value)\n+  ngx.req.set_header(header, new_value)\n+end\n+\n+local function set_request_header(header, value)\n+  ngx.req.set_header(header, value)\n+end\n+\n+local function push_request_header(header, value, req_headers)\n+  if req_headers[header] then\n+    add_request_header(header, value, req_headers)\n+  end\n+end\n+\n+local function add_resp_header(header, value)\n+  local new_value = new_header_value(ngx.header[header], value)\n+  ngx.header[header] = new_value\n+end\n+\n+local function set_resp_header(header, value)\n+  ngx.header[header] = value\n+end\n+\n+local function push_resp_header(header, value)\n+  if ngx.header[header] then\n+    add_resp_header(header, value)\n+  end\n+end\n+\n+local command_functions = {\n+  request = {\n+    add = add_request_header,\n+    set = set_request_header,\n+    push = push_request_header\n+  },\n+  response = {\n+    add = add_resp_header,\n+    set = set_resp_header,\n+    push = push_resp_header\n+  }\n+}\n+\n+-- header_type can be 'request' or 'response'.\n+local function run_commands(commands, header_type)\n+  -- This is here to avoid calling ngx.req.get_headers() in every command\n+  -- applied to the request headers.\n+  local req_headers = {}\n+  if header_type == 'request' then\n+    req_headers = ngx.req.get_headers() or {}\n+  end\n+\n+  for _, command in ipairs(commands) do\n+    local command_func = command_functions[header_type][command.op]\n+    command_func(command.header, command.value, req_headers)","path":"gateway/src/apicast/policy/headers.lua","position":82,"original_position":82,"commit_id":"e80c59d88209356a739d87537d1425958e34584e","original_commit_id":"3a23c8e271449cb356aaff59db2fa37fdb894dc6","user":{"login":"davidor","id":907223,"avatar_url":"https://avatars2.githubusercontent.com/u/907223?v=4","gravatar_id":"","url":"https://api.github.com/users/davidor","html_url":"https://github.com/davidor","followers_url":"https://api.github.com/users/davidor/followers","following_url":"https://api.github.com/users/davidor/following{/other_user}","gists_url":"https://api.github.com/users/davidor/gists{/gist_id}","starred_url":"https://api.github.com/users/davidor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidor/subscriptions","organizations_url":"https://api.github.com/users/davidor/orgs","repos_url":"https://api.github.com/users/davidor/repos","events_url":"https://api.github.com/users/davidor/events{/privacy}","received_events_url":"https://api.github.com/users/davidor/received_events","type":"User","site_admin":false},"body":"Yes. This is passing rq headers to response commands too.\r\nNot sure I follow. what would you call `cache`?","created_at":"2017-11-27T14:43:30Z","updated_at":"2017-11-27T14:43:30Z","html_url":"https://github.com/3scale/apicast/pull/497#discussion_r153214697","pull_request_url":"https://api.github.com/repos/3scale/apicast/pulls/497","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/3scale/apicast/pulls/comments/153214697"},"html":{"href":"https://github.com/3scale/apicast/pull/497#discussion_r153214697"},"pull_request":{"href":"https://api.github.com/repos/3scale/apicast/pulls/497"}},"in_reply_to_id":153210134},"pull_request":{"url":"https://api.github.com/repos/3scale/apicast/pulls/497","id":154168221,"html_url":"https://github.com/3scale/apicast/pull/497","diff_url":"https://github.com/3scale/apicast/pull/497.diff","patch_url":"https://github.com/3scale/apicast/pull/497.patch","issue_url":"https://api.github.com/repos/3scale/apicast/issues/497","number":497,"state":"open","locked":false,"title":"Add headers policy","user":{"login":"davidor","id":907223,"avatar_url":"https://avatars2.githubusercontent.com/u/907223?v=4","gravatar_id":"","url":"https://api.github.com/users/davidor","html_url":"https://github.com/davidor","followers_url":"https://api.github.com/users/davidor/followers","following_url":"https://api.github.com/users/davidor/following{/other_user}","gists_url":"https://api.github.com/users/davidor/gists{/gist_id}","starred_url":"https://api.github.com/users/davidor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidor/subscriptions","organizations_url":"https://api.github.com/users/davidor/orgs","repos_url":"https://api.github.com/users/davidor/repos","events_url":"https://api.github.com/users/davidor/events{/privacy}","received_events_url":"https://api.github.com/users/davidor/received_events","type":"User","site_admin":false},"body":"Closes #490 ","created_at":"2017-11-22T14:30:12Z","updated_at":"2017-11-27T14:43:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b9ef709b807b9580654e0d881f672e25bb53598d","assignee":{"login":"davidor","id":907223,"avatar_url":"https://avatars2.githubusercontent.com/u/907223?v=4","gravatar_id":"","url":"https://api.github.com/users/davidor","html_url":"https://github.com/davidor","followers_url":"https://api.github.com/users/davidor/followers","following_url":"https://api.github.com/users/davidor/following{/other_user}","gists_url":"https://api.github.com/users/davidor/gists{/gist_id}","starred_url":"https://api.github.com/users/davidor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidor/subscriptions","organizations_url":"https://api.github.com/users/davidor/orgs","repos_url":"https://api.github.com/users/davidor/repos","events_url":"https://api.github.com/users/davidor/events{/privacy}","received_events_url":"https://api.github.com/users/davidor/received_events","type":"User","site_admin":false},"assignees":[{"login":"davidor","id":907223,"avatar_url":"https://avatars2.githubusercontent.com/u/907223?v=4","gravatar_id":"","url":"https://api.github.com/users/davidor","html_url":"https://github.com/davidor","followers_url":"https://api.github.com/users/davidor/followers","following_url":"https://api.github.com/users/davidor/following{/other_user}","gists_url":"https://api.github.com/users/davidor/gists{/gist_id}","starred_url":"https://api.github.com/users/davidor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidor/subscriptions","organizations_url":"https://api.github.com/users/davidor/orgs","repos_url":"https://api.github.com/users/davidor/repos","events_url":"https://api.github.com/users/davidor/events{/privacy}","received_events_url":"https://api.github.com/users/davidor/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/3scale/apicast/pulls/497/commits","review_comments_url":"https://api.github.com/repos/3scale/apicast/pulls/497/comments","review_comment_url":"https://api.github.com/repos/3scale/apicast/pulls/comments{/number}","comments_url":"https://api.github.com/repos/3scale/apicast/issues/497/comments","statuses_url":"https://api.github.com/repos/3scale/apicast/statuses/e80c59d88209356a739d87537d1425958e34584e","head":{"label":"3scale:headers-policy","ref":"headers-policy","sha":"e80c59d88209356a739d87537d1425958e34584e","user":{"login":"3scale","id":21415,"avatar_url":"https://avatars0.githubusercontent.com/u/21415?v=4","gravatar_id":"","url":"https://api.github.com/users/3scale","html_url":"https://github.com/3scale","followers_url":"https://api.github.com/users/3scale/followers","following_url":"https://api.github.com/users/3scale/following{/other_user}","gists_url":"https://api.github.com/users/3scale/gists{/gist_id}","starred_url":"https://api.github.com/users/3scale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/3scale/subscriptions","organizations_url":"https://api.github.com/users/3scale/orgs","repos_url":"https://api.github.com/users/3scale/repos","events_url":"https://api.github.com/users/3scale/events{/privacy}","received_events_url":"https://api.github.com/users/3scale/received_events","type":"Organization","site_admin":false},"repo":{"id":53965666,"name":"apicast","full_name":"3scale/apicast","owner":{"login":"3scale","id":21415,"avatar_url":"https://avatars0.githubusercontent.com/u/21415?v=4","gravatar_id":"","url":"https://api.github.com/users/3scale","html_url":"https://github.com/3scale","followers_url":"https://api.github.com/users/3scale/followers","following_url":"https://api.github.com/users/3scale/following{/other_user}","gists_url":"https://api.github.com/users/3scale/gists{/gist_id}","starred_url":"https://api.github.com/users/3scale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/3scale/subscriptions","organizations_url":"https://api.github.com/users/3scale/orgs","repos_url":"https://api.github.com/users/3scale/repos","events_url":"https://api.github.com/users/3scale/events{/privacy}","received_events_url":"https://api.github.com/users/3scale/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/3scale/apicast","description":"3scale api gateway reloaded","fork":false,"url":"https://api.github.com/repos/3scale/apicast","forks_url":"https://api.github.com/repos/3scale/apicast/forks","keys_url":"https://api.github.com/repos/3scale/apicast/keys{/key_id}","collaborators_url":"https://api.github.com/repos/3scale/apicast/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/3scale/apicast/teams","hooks_url":"https://api.github.com/repos/3scale/apicast/hooks","issue_events_url":"https://api.github.com/repos/3scale/apicast/issues/events{/number}","events_url":"https://api.github.com/repos/3scale/apicast/events","assignees_url":"https://api.github.com/repos/3scale/apicast/assignees{/user}","branches_url":"https://api.github.com/repos/3scale/apicast/branches{/branch}","tags_url":"https://api.github.com/repos/3scale/apicast/tags","blobs_url":"https://api.github.com/repos/3scale/apicast/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/3scale/apicast/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/3scale/apicast/git/refs{/sha}","trees_url":"https://api.github.com/repos/3scale/apicast/git/trees{/sha}","statuses_url":"https://api.github.com/repos/3scale/apicast/statuses/{sha}","languages_url":"https://api.github.com/repos/3scale/apicast/languages","stargazers_url":"https://api.github.com/repos/3scale/apicast/stargazers","contributors_url":"https://api.github.com/repos/3scale/apicast/contributors","subscribers_url":"https://api.github.com/repos/3scale/apicast/subscribers","subscription_url":"https://api.github.com/repos/3scale/apicast/subscription","commits_url":"https://api.github.com/repos/3scale/apicast/commits{/sha}","git_commits_url":"https://api.github.com/repos/3scale/apicast/git/commits{/sha}","comments_url":"https://api.github.com/repos/3scale/apicast/comments{/number}","issue_comment_url":"https://api.github.com/repos/3scale/apicast/issues/comments{/number}","contents_url":"https://api.github.com/repos/3scale/apicast/contents/{+path}","compare_url":"https://api.github.com/repos/3scale/apicast/compare/{base}...{head}","merges_url":"https://api.github.com/repos/3scale/apicast/merges","archive_url":"https://api.github.com/repos/3scale/apicast/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/3scale/apicast/downloads","issues_url":"https://api.github.com/repos/3scale/apicast/issues{/number}","pulls_url":"https://api.github.com/repos/3scale/apicast/pulls{/number}","milestones_url":"https://api.github.com/repos/3scale/apicast/milestones{/number}","notifications_url":"https://api.github.com/repos/3scale/apicast/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/3scale/apicast/labels{/name}","releases_url":"https://api.github.com/repos/3scale/apicast/releases{/id}","deployments_url":"https://api.github.com/repos/3scale/apicast/deployments","created_at":"2016-03-15T17:41:51Z","updated_at":"2017-11-22T01:14:30Z","pushed_at":"2017-11-27T14:42:01Z","git_url":"git://github.com/3scale/apicast.git","ssh_url":"git@github.com:3scale/apicast.git","clone_url":"https://github.com/3scale/apicast.git","svn_url":"https://github.com/3scale/apicast","homepage":"","size":1963,"stargazers_count":57,"watchers_count":57,"language":"Lua","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":41,"mirror_url":null,"archived":false,"open_issues_count":37,"forks":41,"open_issues":37,"watchers":57,"default_branch":"master"}},"base":{"label":"3scale:master","ref":"master","sha":"3063ce67e8a8f79ff633572a3cbdcaccedef43ef","user":{"login":"3scale","id":21415,"avatar_url":"https://avatars0.githubusercontent.com/u/21415?v=4","gravatar_id":"","url":"https://api.github.com/users/3scale","html_url":"https://github.com/3scale","followers_url":"https://api.github.com/users/3scale/followers","following_url":"https://api.github.com/users/3scale/following{/other_user}","gists_url":"https://api.github.com/users/3scale/gists{/gist_id}","starred_url":"https://api.github.com/users/3scale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/3scale/subscriptions","organizations_url":"https://api.github.com/users/3scale/orgs","repos_url":"https://api.github.com/users/3scale/repos","events_url":"https://api.github.com/users/3scale/events{/privacy}","received_events_url":"https://api.github.com/users/3scale/received_events","type":"Organization","site_admin":false},"repo":{"id":53965666,"name":"apicast","full_name":"3scale/apicast","owner":{"login":"3scale","id":21415,"avatar_url":"https://avatars0.githubusercontent.com/u/21415?v=4","gravatar_id":"","url":"https://api.github.com/users/3scale","html_url":"https://github.com/3scale","followers_url":"https://api.github.com/users/3scale/followers","following_url":"https://api.github.com/users/3scale/following{/other_user}","gists_url":"https://api.github.com/users/3scale/gists{/gist_id}","starred_url":"https://api.github.com/users/3scale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/3scale/subscriptions","organizations_url":"https://api.github.com/users/3scale/orgs","repos_url":"https://api.github.com/users/3scale/repos","events_url":"https://api.github.com/users/3scale/events{/privacy}","received_events_url":"https://api.github.com/users/3scale/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/3scale/apicast","description":"3scale api gateway reloaded","fork":false,"url":"https://api.github.com/repos/3scale/apicast","forks_url":"https://api.github.com/repos/3scale/apicast/forks","keys_url":"https://api.github.com/repos/3scale/apicast/keys{/key_id}","collaborators_url":"https://api.github.com/repos/3scale/apicast/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/3scale/apicast/teams","hooks_url":"https://api.github.com/repos/3scale/apicast/hooks","issue_events_url":"https://api.github.com/repos/3scale/apicast/issues/events{/number}","events_url":"https://api.github.com/repos/3scale/apicast/events","assignees_url":"https://api.github.com/repos/3scale/apicast/assignees{/user}","branches_url":"https://api.github.com/repos/3scale/apicast/branches{/branch}","tags_url":"https://api.github.com/repos/3scale/apicast/tags","blobs_url":"https://api.github.com/repos/3scale/apicast/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/3scale/apicast/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/3scale/apicast/git/refs{/sha}","trees_url":"https://api.github.com/repos/3scale/apicast/git/trees{/sha}","statuses_url":"https://api.github.com/repos/3scale/apicast/statuses/{sha}","languages_url":"https://api.github.com/repos/3scale/apicast/languages","stargazers_url":"https://api.github.com/repos/3scale/apicast/stargazers","contributors_url":"https://api.github.com/repos/3scale/apicast/contributors","subscribers_url":"https://api.github.com/repos/3scale/apicast/subscribers","subscription_url":"https://api.github.com/repos/3scale/apicast/subscription","commits_url":"https://api.github.com/repos/3scale/apicast/commits{/sha}","git_commits_url":"https://api.github.com/repos/3scale/apicast/git/commits{/sha}","comments_url":"https://api.github.com/repos/3scale/apicast/comments{/number}","issue_comment_url":"https://api.github.com/repos/3scale/apicast/issues/comments{/number}","contents_url":"https://api.github.com/repos/3scale/apicast/contents/{+path}","compare_url":"https://api.github.com/repos/3scale/apicast/compare/{base}...{head}","merges_url":"https://api.github.com/repos/3scale/apicast/merges","archive_url":"https://api.github.com/repos/3scale/apicast/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/3scale/apicast/downloads","issues_url":"https://api.github.com/repos/3scale/apicast/issues{/number}","pulls_url":"https://api.github.com/repos/3scale/apicast/pulls{/number}","milestones_url":"https://api.github.com/repos/3scale/apicast/milestones{/number}","notifications_url":"https://api.github.com/repos/3scale/apicast/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/3scale/apicast/labels{/name}","releases_url":"https://api.github.com/repos/3scale/apicast/releases{/id}","deployments_url":"https://api.github.com/repos/3scale/apicast/deployments","created_at":"2016-03-15T17:41:51Z","updated_at":"2017-11-22T01:14:30Z","pushed_at":"2017-11-27T14:42:01Z","git_url":"git://github.com/3scale/apicast.git","ssh_url":"git@github.com:3scale/apicast.git","clone_url":"https://github.com/3scale/apicast.git","svn_url":"https://github.com/3scale/apicast","homepage":"","size":1963,"stargazers_count":57,"watchers_count":57,"language":"Lua","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":41,"mirror_url":null,"archived":false,"open_issues_count":37,"forks":41,"open_issues":37,"watchers":57,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/3scale/apicast/pulls/497"},"html":{"href":"https://github.com/3scale/apicast/pull/497"},"issue":{"href":"https://api.github.com/repos/3scale/apicast/issues/497"},"comments":{"href":"https://api.github.com/repos/3scale/apicast/issues/497/comments"},"review_comments":{"href":"https://api.github.com/repos/3scale/apicast/pulls/497/comments"},"review_comment":{"href":"https://api.github.com/repos/3scale/apicast/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/3scale/apicast/pulls/497/commits"},"statuses":{"href":"https://api.github.com/repos/3scale/apicast/statuses/e80c59d88209356a739d87537d1425958e34584e"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"davidor"}}