MCPcopy Create free account
hub / github.com/acl-dev/acl / http_util_req_new

Function http_util_req_new

lib_protocol/src/http/http_util.c:27–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27HTTP_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
75HTTP_UTIL *http_util_res_new(int status)
76{

Callers 3

get_urlFunction · 0.85
http_util_dump_urlFunction · 0.85

Calls 7

acl_msg_errorFunction · 0.85
acl_strncasecmpFunction · 0.85
http_hdr_req_createFunction · 0.85
http_hdr_res_newFunction · 0.85
http_res_newFunction · 0.85
acl_vstring_allocFunction · 0.85
http_hdr_req_hostFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…