One-shot HTTP exchange. Returns response length, 0 on connect failure. */
| 121 | |
| 122 | /* One-shot HTTP exchange. Returns response length, 0 on connect failure. */ |
| 123 | static int th_http(int port, const char *request, char *resp, size_t respsz) { |
| 124 | th_sock_t s = th_connect(port); |
| 125 | if (s == TH_SOCK_BAD) |
| 126 | return 0; |
| 127 | if (th_send_all(s, request, strlen(request)) != 0) { |
| 128 | th_sock_close(s); |
| 129 | return 0; |
| 130 | } |
| 131 | int n = th_recv_until_close(s, resp, respsz); |
| 132 | th_sock_close(s); |
| 133 | return n; |
| 134 | } |
| 135 | |
| 136 | /* HTTP status code from a raw response ("HTTP/1.1 404 ..."), or -1. */ |
| 137 | static int th_status(const char *resp) { |
no test coverage detected