| 28 | end |
| 29 | }}} |
| 30 | |
| 31 | == Checking that the proxy is running == |
| 32 | |
| 33 | Your plugin should check that the proxy is running, by querying its API version string. |
| 34 | |
| 35 | {{{ |
| 36 | local ProxyApiVersion |
| 37 | local t = {} |
| 38 | local request, code = http.request({ |
| 39 | url = "http://localhost:2529/version", |
| 40 | create = socketWithTimeout(2), |
| 41 | sink = ltn12.sink.table(t) |
| 42 | }) |
| 43 | |
| 44 | if (request == nil and code == "timeout") then |
| 45 | -- Proxy may be busy (retry). |
| 46 | elseif (request == nil and code ~= "closed") then |
| 47 | -- Proxy not running. |
| 48 | else |
| 49 | -- Proxy is running, note its version number. |
| 50 | ProxyApiVersion = table.concat(t) |