chilcano commented on issue #9818:
URL: https://github.com/apache/apisix/issues/9818#issuecomment-1632868998

   Thanks @qwzhou89 
   I've tried `ngx.encode_base64` and overriding `ctx.var.upstream_uri`. That 
override the uri, however that updated uri is not persisted i the 2nd call.
   
   This is my route:
   ```sh
   curl -i http://127.0.0.1:9180/apisix/admin/routes/5 -H 'X-API-KEY: 
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
      "methods":["GET"],
      "uri":"/api01/*",
      "plugins":{
         "serverless-pre-function": {
            "phase": "rewrite",
            "functions": [
               "return function(conf, ctx) 
                  local req_uri_real = ctx.var.real_request_uri 
                  local upstream_url_ini = ctx.var.upstream_uri
                  local req_uri_matched = ctx.curr_req_matched._path
                  local req_uri_b64 = ngx.encode_base64(req_uri_real)
                  --ctx.var.upstream_uri = \"/base64/\" .. req_uri_b64
                  ctx.var.upstream_uri = \"/\" .. req_uri_b64
                  ngx.log(ngx.ERR, \"req_uri_real: \" .. req_uri_real .. \", 
req_uri_b64: \" .. req_uri_b64); 
               end"
            ]
         },
         "proxy-rewrite":{
            "regex_uri":[
               "^/(.*)",
               "/api02/base64/$1"
            ],
            "host":"echo-api.3scale.net",
            "headers":{
               "X-Apikey":"1234567890",
               "Content-Type":"application/json"
            }
         }
      },
      "upstream": {
         "type": "roundrobin",
         "scheme": "https",
         "nodes": {
            "echo-api.3scale.net": 1
         }
      }
   }'
   ``` 
   and this the response:
   ```sh
   curl http://127.0.0.1:9080/api01/abc123 -s | jq .
   
   {
     "method": "GET",
     "path": "/api02/base64/api01/abc123",
     "args": "",
     "body": "",
     "headers": {
       "HTTP_VERSION": "HTTP/1.1",
       "HTTP_HOST": "echo-api.3scale.net",
       "HTTP_X_REAL_IP": "172.18.0.1",
       "HTTP_X_FORWARDED_FOR": "172.18.0.1,2.120.146.198",
       "HTTP_X_FORWARDED_PROTO": "https",
       "HTTP_X_FORWARDED_HOST": "127.0.0.1",
       "HTTP_X_FORWARDED_PORT": "9080",
       "HTTP_USER_AGENT": "curl/8.1.2",
       "HTTP_ACCEPT": "*/*",
       "HTTP_X_APIKEY": "1234567890",
       "CONTENT_TYPE": "application/json",
       "HTTP_X_ENVOY_EXTERNAL_ADDRESS": "2.120.146.198",
       "HTTP_X_REQUEST_ID": "3c2d1950-cdc4-472b-b08d-8aeca047c320",
       "HTTP_X_ENVOY_EXPECTED_RQ_TIMEOUT_MS": "15000"
     },
     "uuid": "09f0ee66-1f36-40a1-bdc2-8b5b868be8dc"
   }
   ```
   And if I change to `serverless-post-function` with `"phase": "access"` I 
have this:
   ```sh
   curl http://127.0.0.1:9080/api01/abc123 -s | jq .
   {
     "method": "GET",
     "path": "/L2FwaTAxL2FiYzEyMw==",
     "args": "",
     "body": "",
     "headers": {
       "HTTP_VERSION": "HTTP/1.1",
       "HTTP_HOST": "echo-api.3scale.net",
       "HTTP_X_REAL_IP": "172.18.0.1",
       "HTTP_X_FORWARDED_FOR": "172.18.0.1,2.120.146.198",
       "HTTP_X_FORWARDED_PROTO": "https",
       "HTTP_X_FORWARDED_HOST": "127.0.0.1",
       "HTTP_X_FORWARDED_PORT": "9080",
       "HTTP_USER_AGENT": "curl/8.1.2",
       "HTTP_ACCEPT": "*/*",
       "HTTP_X_APIKEY": "1234567890",
       "CONTENT_TYPE": "application/json",
       "HTTP_X_ENVOY_EXTERNAL_ADDRESS": "2.120.146.198",
       "HTTP_X_REQUEST_ID": "f67a5586-e312-49ae-9496-dfac3d1026bc",
       "HTTP_X_ENVOY_EXPECTED_RQ_TIMEOUT_MS": "15000"
     },
     "uuid": "e499d156-e65f-439f-a45e-4f8cfb371238"
   }
   
   ```
   
   You will see that i get `"path": "/api02/base64/api01/abc123"` and `"path": 
"/L2FwaTAxL2FiYzEyMw=="` respectively when it should be `"path": 
"/api02/base64/L2FwaTAxL2FiYzEyMw=="`.
   
   Am missing something?.
   Appreciate your support.
   
   Kind regards.
   
   
   


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to