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

Function http_hdr_req_create

lib_protocol/src/http/http_hdr_req.c:194–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192}
193
194HTTP_HDR_REQ *http_hdr_req_create(const char *url,
195 const char *method, const char *version)
196{
197 HTTP_HDR_REQ *hdr_req;
198 ACL_VSTRING *req_line = acl_vstring_alloc(256);
199 HTTP_HDR_ENTRY *entry;
200 char proto[32];
201 const char *ptr;
202 static char *__user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0"
203 "; zh-CN; rv:1.9.0.3) Gecko/2008092417 ACL/3.5.1";
204
205 if (url == NULL || *url == 0) {
206 acl_msg_error("%s(%d): url invalid", __FUNCTION__, __LINE__);
207 acl_vstring_free(req_line);
208 return NULL;
209 }
210 if (method == NULL || *method == 0) {
211 acl_msg_error("%s(%d): method invalid", __FUNCTION__, __LINE__);
212 acl_vstring_free(req_line);
213 return NULL;
214 }
215 if (version == NULL || *version == 0) {
216 acl_msg_error("%s(%d): version invalid", __FUNCTION__, __LINE__);
217 acl_vstring_free(req_line);
218 return NULL;
219 }
220
221 acl_vstring_strcpy(req_line, method);
222 acl_vstring_strcat(req_line, " ");
223
224 if (strncasecmp(url, "http://", sizeof("http://") - 1) == 0) {
225 url += sizeof("http://") - 1;
226 ACL_SAFE_STRNCPY(proto, "http", sizeof(proto));
227 } else if (strncasecmp(url, "https://", sizeof("https://") - 1) == 0) {
228 url += sizeof("https://") -1;
229 ACL_SAFE_STRNCPY(proto, "https", sizeof(proto));
230 } else {
231 ACL_SAFE_STRNCPY(proto, "http", sizeof(proto));
232 }
233
234 ptr = strchr(url, '/');
235 if (ptr) {
236 acl_vstring_strcat(req_line, ptr);
237 } else {
238 ACL_VSTRING_ADDCH(req_line, '/');
239 ACL_VSTRING_TERMINATE(req_line);
240 }
241
242 acl_vstring_strcat(req_line, " ");
243 acl_vstring_strcat(req_line, version);
244
245 entry = http_hdr_entry_new(acl_vstring_str(req_line));
246 acl_vstring_free(req_line);
247
248 if (entry == NULL) {
249 acl_msg_error("%s(%d): http_hdr_entry_new return null for (%s)",
250 __FUNCTION__, __LINE__, acl_vstring_str(req_line));
251 return NULL;

Callers 6

on_connectFunction · 0.85
DoRequestThreadMethod · 0.85
get_urlFunction · 0.85
on_connectFunction · 0.85
http_util_req_newFunction · 0.85
http_client_post_requestFunction · 0.85

Calls 13

acl_vstring_allocFunction · 0.85
acl_msg_errorFunction · 0.85
acl_vstring_freeFunction · 0.85
acl_vstring_strcpyFunction · 0.85
acl_vstring_strcatFunction · 0.85
strncasecmpFunction · 0.85
http_hdr_entry_newFunction · 0.85
http_hdr_req_newFunction · 0.85
http_hdr_append_entryFunction · 0.85
http_hdr_req_line_parseFunction · 0.85
http_hdr_req_freeFunction · 0.85
__get_host_from_urlFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…