| 192 | } |
| 193 | |
| 194 | HTTP_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; |
no test coverage detected
searching dependent graphs…