laz-xyr commented on issue #12641:
URL: https://github.com/apache/apisix/issues/12641#issuecomment-3707932005

   Local tlshandshake test 
   <details>
   <summary> t/node/healthcheck4.t </summary>
   
   ``` t
   
   === TEST 4: mtls check via socket:tlshandshake
   --- config
       location /t {
           content_by_lua_block {
   
               local sock = ngx.socket.tcp()
               sock:settimeout(6000) 
   
               local ok, err = sock:connect("127.0.0.1", 8765)
               if not ok then
                   ngx.say("err: ", err)
                   return
               end
   
               local session, err = sock:tlshandshake(opts)
               if not session then
                   ngx.say("err: ", err)
                   sock:close()
                   ngx.status = 500
                   return
               end
   
               local req = "GET /healthz HTTP/1.1\r\nConnection: close\r\nHost: 
127.0.0.1\r\n\r\n"
               ok, err = sock:send(req)
               if not ok then
                   ngx.say("err: ", err)
                   sock:close()
                   ngx.status = 500
                   return
               end
   
               local response, err = sock:receive()
               if not response then
                   ngx.say("err: ", err)
                   sock:close()
                   ngx.status = 500
                   return
               end
   
               local re_find = ngx.re.find
               local from, to = re_find(response,
                             [[^HTTP/\d+\.\d+\s+(\d+)]],
                             "joi", nil, 1)
               local status
   
               if from then
                   status = tonumber(response:sub(from, to))
               else
                   status = 500
               end
   
               ngx.status = status
               ngx.say(response)
           }
           
       }
   --- request
   GET /t
   --- response_body
   HTTP/1.1 200 OK
   --- no_error_log
   
   ```
   
   </details>
   


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