| 25 | } |
| 26 | |
| 27 | HTTP_UTIL *http_util_req_new(const char *url, const char *method) |
| 28 | { |
| 29 | const char *myname = "http_util_req_new"; |
| 30 | HTTP_UTIL *http_util = (HTTP_UTIL*) acl_mycalloc(1, sizeof(HTTP_UTIL)); |
| 31 | const char *ptr, *host; |
| 32 | |
| 33 | if (url == NULL || *url == 0) { |
| 34 | acl_msg_error("%s(%d): url invalid", myname, __LINE__); |
| 35 | return (NULL); |
| 36 | } |
| 37 | if (method == NULL || *method == 0) { |
| 38 | acl_msg_error("%s(%d): method invalid", myname, __LINE__); |
| 39 | return (NULL); |
| 40 | } |
| 41 | |
| 42 | if (acl_strncasecmp(url, "http://", sizeof("http://") - 1) != 0) { |
| 43 | acl_msg_error("%s(%d): url(%s) invalid", myname, __LINE__, url); |
| 44 | return (NULL); |
| 45 | } |
| 46 | |
| 47 | if (strcmp(method, "GET") != 0 && strcmp(method, "POST") != 0 |
| 48 | && strcmp(method, "HEAD") != 0 && strcmp(method, "CONNECT") != 0) |
| 49 | { |
| 50 | acl_msg_error("%s(%d): method(%s) invalid", myname, __LINE__, method); |
| 51 | return (NULL); |
| 52 | } |
| 53 | |
| 54 | http_util->hdr_req = http_hdr_req_create(url, method, "HTTP/1.1"); |
| 55 | http_util->hdr_res = http_hdr_res_new(); |
| 56 | http_util->http_res = http_res_new(http_util->hdr_res); |
| 57 | http_util->req_buf = acl_vstring_alloc(4096); |
| 58 | |
| 59 | host = http_hdr_req_host(http_util->hdr_req); |
| 60 | if (host) { |
| 61 | ptr = strchr(host, ':'); |
| 62 | if (ptr == NULL) |
| 63 | snprintf(http_util->server_addr, |
| 64 | sizeof(http_util->server_addr), "%s:80", host); |
| 65 | else |
| 66 | ACL_SAFE_STRNCPY(http_util->server_addr, host, |
| 67 | sizeof(http_util->server_addr)); |
| 68 | } |
| 69 | |
| 70 | http_util->conn_timeout = 10; |
| 71 | http_util->rw_timeout = 10; |
| 72 | return (http_util); |
| 73 | } |
| 74 | |
| 75 | HTTP_UTIL *http_util_res_new(int status) |
| 76 | { |
no test coverage detected
searching dependent graphs…