You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/06/13 15:33:16 UTC

[GitHub] [incubator-apisix] Akayeshmantha opened a new pull request #1708: add header filter and access phases.

Akayeshmantha opened a new pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708


   
   Fix #1225 
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] membphis commented on pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
membphis commented on pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#issuecomment-646638433


   @Akayeshmantha merged, many thx


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r441532599



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +94,22 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.access(conf, ctx)
+    local auth_header = core.request.header(ctx, "Authorization")
+
+    if auth_header and auth_header == "userpass" then
+        return 200, "authorized body"
+    end
+    return 401, "unauthorized body"

Review comment:
       So we talked about keeping this very simple. I thought maybe  to add the flow of basic auth plugin to extract username and PWD but we just want to convey the idea as per @agile6v. Like if someone need to access a protected resource in the access phase we need to have  some kind of an auth workflow 
   
   WDYT @agile6v 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] agile6v commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
agile6v commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r442245798



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +102,23 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.access(conf, ctx)
+    local auth_header = core.request.header(ctx, "Authorization")

Review comment:
       This `core.request.header` function returns the value of the specified header. So it should be like this:
   ```
   local value = core.request.header(ctx,  conf.auth_header)
   if value ~= conf.auth_value then
       return 401, "unauthorized request."
   end
   ```
   In addition, the boundary conditions need to be considered.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] membphis commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
membphis commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r441597633



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +102,23 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.access(conf, ctx)
+    local auth_header = core.request.header(ctx, "Authorization")
+
+    if conf.auth_header == "Authorization" and conf.auth_value == "userpass" then
+            return 200, "authorized body"
+    end

Review comment:
       `local auth_header` is it useless?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r441593989



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +94,22 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.access(conf, ctx)
+    local auth_header = core.request.header(ctx, "Authorization")
+
+    if auth_header and auth_header == "userpass" then
+        return 200, "authorized body"
+    end
+    return 401, "unauthorized body"

Review comment:
       Hi @membphis  so I pushed the latest one 

##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +94,22 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.access(conf, ctx)
+    local auth_header = core.request.header(ctx, "Authorization")
+
+    if auth_header and auth_header == "userpass" then
+        return 200, "authorized body"
+    end
+    return 401, "unauthorized body"

Review comment:
       of course with more tests.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] membphis commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
membphis commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r441257720



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +94,22 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.access(conf, ctx)
+    local auth_header = core.request.header(ctx, "Authorization")
+
+    if auth_header and auth_header == "userpass" then
+        return 200, "authorized body"
+    end
+    return 401, "unauthorized body"

Review comment:
       I was confused about this process. @agile6v Do you think we should keep this?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] membphis commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
membphis commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r442226542



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +102,23 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.access(conf, ctx)
+    local auth_header = core.request.header(ctx, "Authorization")
+
+    if conf.auth_header == "Authorization" and conf.auth_value == "userpass" then
+            return 200, "authorized body"
+    end

Review comment:
       ok, got it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#issuecomment-646626547


   @agile6v  @membphis  I think we can merge this right and will start on working the other phases 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#issuecomment-646449946


   @membphis thank you 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] membphis commented on pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
membphis commented on pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#issuecomment-646018856


   @Akayeshmantha I think you can add some doc things, then we can merge this PR soon


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#issuecomment-646145465


   @membphis  this error in travis not related to test cases. Ca we restart the job


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] membphis commented on pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
membphis commented on pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#issuecomment-646443514


   I have restarted it.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] membphis commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
membphis commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r441256766



##########
File path: t/plugin/echo.t
##########
@@ -202,8 +212,32 @@ passed
 === TEST 6: access without upstream body change
 --- request
 GET /hello
---- response_body
-before the body modification hello world
+--- more_headers
+Authorization: userpass
+--- response_body chomp
+before the body modification authorized body
 --- no_error_log
 [error]
 --- wait: 0.2
+
+
+
+=== TEST 7: access with wrong auth header value throws 401
+--- request
+GET /hello
+--- more_headers
+Authorization: password
+--- error_code: 401
+--- response_body chomp

Review comment:
       need to check the response header

##########
File path: t/plugin/echo.t
##########
@@ -202,8 +212,32 @@ passed
 === TEST 6: access without upstream body change
 --- request
 GET /hello
---- response_body
-before the body modification hello world
+--- more_headers
+Authorization: userpass
+--- response_body chomp
+before the body modification authorized body
 --- no_error_log
 [error]
 --- wait: 0.2
+
+
+
+=== TEST 7: access with wrong auth header value throws 401
+--- request
+GET /hello
+--- more_headers
+Authorization: password
+--- error_code: 401
+--- response_body chomp
+before the body modification unauthorized body
+--- wait: 0.2
+
+
+
+=== TEST 8: access without auth header value throws 401
+--- request
+GET /hello
+--- error_code: 401

Review comment:
       ditto

##########
File path: apisix/plugins/echo.lua
##########
@@ -31,6 +34,11 @@ local schema = {
         after_body = {
             description = "body after the modification of filter phase.",
             type = "string"
+        },
+        headers = {
+            description = "new headers for repsonse",
+            type = "object",
+            minProperties = 1,

Review comment:
       if the answer is YES, then we need to update the process: https://github.com/apache/incubator-apisix/pull/1708/files#diff-32537bd33cf9a44d9dd277b87d1ce5f9R82

##########
File path: apisix/plugins/echo.lua
##########
@@ -31,6 +34,11 @@ local schema = {
         after_body = {
             description = "body after the modification of filter phase.",
             type = "string"
+        },
+        headers = {
+            description = "new headers for repsonse",
+            type = "object",
+            minProperties = 1,

Review comment:
       can we only require the `headers`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] membphis commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
membphis commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r441581711



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +94,22 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.access(conf, ctx)
+    local auth_header = core.request.header(ctx, "Authorization")
+
+    if auth_header and auth_header == "userpass" then
+        return 200, "authorized body"
+    end
+    return 401, "unauthorized body"

Review comment:
       should we drop this code? https://github.com/apache/incubator-apisix/pull/1708/commits/dcbcc69a1c334761d01d3e85bfb3d60c35b90413#diff-32537bd33cf9a44d9dd277b87d1ce5f9R100-R104




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r441531263



##########
File path: apisix/plugins/echo.lua
##########
@@ -31,6 +34,11 @@ local schema = {
         after_body = {
             description = "body after the modification of filter phase.",
             type = "string"
+        },
+        headers = {
+            description = "new headers for repsonse",
+            type = "object",
+            minProperties = 1,

Review comment:
       I prefer to keep them since it is possible for someone to change the body of the response in the body filter part phase from what the user inputs. It is easy to understand that way.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r442258275



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +102,23 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.access(conf, ctx)
+    local auth_header = core.request.header(ctx, "Authorization")

Review comment:
       @agile6v 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] agile6v commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
agile6v commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r441604796



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +102,23 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.access(conf, ctx)
+    local auth_header = core.request.header(ctx, "Authorization")
+
+    if conf.auth_header == "Authorization" and conf.auth_value == "userpass" then
+            return 200, "authorized body"
+    end

Review comment:
       Yes. I have communicated with @Akayeshmantha on slack. And then review when the changes are completed?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] membphis merged pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
membphis merged pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r441601037



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +102,23 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.access(conf, ctx)
+    local auth_header = core.request.header(ctx, "Authorization")
+
+    if conf.auth_header == "Authorization" and conf.auth_value == "userpass" then
+            return 200, "authorized body"
+    end

Review comment:
       @agile6v  wdyt ? 
   
   I think at least we should showcase the workflow to pass auth header and then based on it give access in the access phase




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#issuecomment-644815546


   @agile6v  pushed the changes 
   @membphis 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] agile6v commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
agile6v commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r441556966



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +94,22 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.access(conf, ctx)
+    local auth_header = core.request.header(ctx, "Authorization")
+
+    if auth_header and auth_header == "userpass" then
+        return 200, "authorized body"
+    end
+    return 401, "unauthorized body"

Review comment:
       Hi @Akayeshmantha I mean we could specify the header and value, which is flexible and simple.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] agile6v commented on a change in pull request #1708: add header filter and access phases.

Posted by GitBox <gi...@apache.org>.
agile6v commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r439780581



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +92,21 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.header_filter(conf, ctx)
+    if conf.headers_arr then
+        local field_cnt = #conf.headers_arr
+        for i = 1, field_cnt, 2 do
+            ngx.header[conf.headers_arr[i]] = conf.headers_arr[i+1]
+        end
+    end
+end
+
+function _M.access(conf, ctx)
+    local auth_header = ngx.headers["Authorization"]
+    if not auth_header then
+        return 401, { message = conf.unathorized_body }
+    end
+    return 200, { message = conf.authorized_body }

Review comment:
       Can the value corresponding to the auth header be verified?

##########
File path: apisix/plugins/echo.lua
##########
@@ -52,6 +56,24 @@ local _M = {
 
 
 function _M.check_schema(conf)
+
+    if conf.headers then

Review comment:
       `headers` needs to be added in schema.

##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +92,21 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.header_filter(conf, ctx)
+    if conf.headers_arr then
+        local field_cnt = #conf.headers_arr
+        for i = 1, field_cnt, 2 do
+            ngx.header[conf.headers_arr[i]] = conf.headers_arr[i+1]
+        end
+    end
+end
+
+function _M.access(conf, ctx)
+    local auth_header = ngx.headers["Authorization"]
+    if not auth_header then
+        return 401, { message = conf.unathorized_body }

Review comment:
       `unathorized_body ` need to be added in schema.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r440345343



##########
File path: apisix/plugins/echo.lua
##########
@@ -52,6 +56,24 @@ local _M = {
 
 
 function _M.check_schema(conf)
+
+    if conf.headers then

Review comment:
       yes will add them wanted to get an idea first weather the flow is correct.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#issuecomment-646028676


   @membphis  sure so I discussed with @agile6v  about giving proper documentation saying what this phase does and what we are showcasing from our examples. So, in the end, he mentioned let's finish up all the phases and start working on the documenting.
   
   But already the plugin documentation in place.  
   
   cc :- @agile6v 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] agile6v commented on a change in pull request #1708: add header filter and access phases.

Posted by GitBox <gi...@apache.org>.
agile6v commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r439780322



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +92,21 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.header_filter(conf, ctx)
+    if conf.headers_arr then
+        local field_cnt = #conf.headers_arr
+        for i = 1, field_cnt, 2 do
+            ngx.header[conf.headers_arr[i]] = conf.headers_arr[i+1]
+        end
+    end
+end
+
+function _M.access(conf, ctx)
+    local auth_header = ngx.headers["Authorization"]

Review comment:
       It's best to specify the auth header. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r440345136



##########
File path: apisix/plugins/echo.lua
##########
@@ -70,4 +92,21 @@ function _M.body_filter(conf, ctx)
     ngx.arg[2] = true
 end
 
+function _M.header_filter(conf, ctx)
+    if conf.headers_arr then
+        local field_cnt = #conf.headers_arr
+        for i = 1, field_cnt, 2 do
+            ngx.header[conf.headers_arr[i]] = conf.headers_arr[i+1]
+        end
+    end
+end
+
+function _M.access(conf, ctx)
+    local auth_header = ngx.headers["Authorization"]
+    if not auth_header then
+        return 401, { message = conf.unathorized_body }
+    end
+    return 200, { message = conf.authorized_body }

Review comment:
       @agile6v  you mean like we do in the basic-auth plugin extract the values and check ?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r441530137



##########
File path: t/plugin/echo.t
##########
@@ -202,8 +212,32 @@ passed
 === TEST 6: access without upstream body change
 --- request
 GET /hello
---- response_body
-before the body modification hello world
+--- more_headers
+Authorization: userpass
+--- response_body chomp
+before the body modification authorized body
 --- no_error_log
 [error]
 --- wait: 0.2
+
+
+
+=== TEST 7: access with wrong auth header value throws 401
+--- request
+GET /hello
+--- more_headers
+Authorization: password
+--- error_code: 401
+--- response_body chomp

Review comment:
       done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on a change in pull request #1708: feature(echo): support header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on a change in pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#discussion_r440760092



##########
File path: apisix/plugins/echo.lua
##########
@@ -52,6 +56,24 @@ local _M = {
 
 
 function _M.check_schema(conf)
+
+    if conf.headers then

Review comment:
       added




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-apisix] Akayeshmantha commented on pull request #1708: add header filter and access phases.

Posted by GitBox <gi...@apache.org>.
Akayeshmantha commented on pull request #1708:
URL: https://github.com/apache/incubator-apisix/pull/1708#issuecomment-643639119


   @agile6v 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org