X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_request_api.c;h=96a613fd66a1a1fb5e95e10d7d21c27bcac7da36;hb=6c4aac679c57cea2e3f7524974509595dc1a31a2;hp=b101558d54952b040e5b514234aa621a275e4e8a;hpb=f1ad647efef34bd909e850fa5c132bbfd3348a71;p=m6w6%2Fext-http diff --git a/http_request_api.c b/http_request_api.c index b101558..96a613f 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -450,8 +450,6 @@ PHP_HTTP_API void _http_request_defaults(http_request *request) #if HTTP_CURL_VERSION(7,14,1) HTTP_CURL_OPT(CURLOPT_COOKIELIST, NULL); #endif - HTTP_CURL_OPT(CURLOPT_COOKIEFILE, NULL); - HTTP_CURL_OPT(CURLOPT_COOKIEJAR, NULL); HTTP_CURL_OPT(CURLOPT_RANGE, NULL); HTTP_CURL_OPT(CURLOPT_RESUME_FROM, 0); HTTP_CURL_OPT(CURLOPT_MAXFILESIZE, 0); @@ -757,27 +755,22 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } } -#if HTTP_CURL_VERSION(7,14,1) - /* reset cookies */ - if ((zoption = http_request_option(request, options, "resetcookies", IS_BOOL)) && Z_LVAL_P(zoption)) { - HTTP_CURL_OPT(CURLOPT_COOKIELIST, "ALL"); - } -#endif - /* session cookies */ if ((zoption = http_request_option(request, options, "cookiesession", IS_BOOL))) { - if (Z_LVAL_P(zoption)) { + if (Z_BVAL_P(zoption)) { /* accept cookies for this session */ HTTP_CURL_OPT(CURLOPT_COOKIEFILE, ""); } else { - /* reset session cookies */ + /* don't load session cookies from cookiestore */ HTTP_CURL_OPT(CURLOPT_COOKIESESSION, 1); } } /* cookiestore, read initial cookies from that file and store cookies back into that file */ - if ((zoption = http_request_option(request, options, "cookiestore", IS_STRING)) && Z_STRLEN_P(zoption)) { - HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_P(zoption), return FAILURE); + if ((zoption = http_request_option(request, options, "cookiestore", IS_STRING))) { + if (Z_STRLEN_P(zoption)) { + HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_P(zoption), return FAILURE); + } HTTP_CURL_OPT(CURLOPT_COOKIEFILE, Z_STRVAL_P(zoption)); HTTP_CURL_OPT(CURLOPT_COOKIEJAR, Z_STRVAL_P(zoption)); } @@ -838,23 +831,22 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } /* request method */ - switch (request->meth) - { + switch (request->meth) { case HTTP_GET: HTTP_CURL_OPT(CURLOPT_HTTPGET, 1); - break; + break; case HTTP_HEAD: HTTP_CURL_OPT(CURLOPT_NOBODY, 1); - break; + break; case HTTP_POST: HTTP_CURL_OPT(CURLOPT_POST, 1); - break; + break; case HTTP_PUT: HTTP_CURL_OPT(CURLOPT_UPLOAD, 1); - break; + break; default: if (http_request_method_exists(0, request->meth, NULL)) { @@ -863,20 +855,19 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Unsupported request method: %d (%s)", request->meth, request->url); return FAILURE; } - break; + break; } /* attach request body */ if (request->body && (request->meth != HTTP_GET) && (request->meth != HTTP_HEAD) && (request->meth != HTTP_OPTIONS)) { - switch (request->body->type) - { + switch (request->body->type) { case HTTP_REQUEST_BODY_EMPTY: /* nothing */ - break; + break; case HTTP_REQUEST_BODY_CURLPOST: HTTP_CURL_OPT(CURLOPT_HTTPPOST, (struct curl_httppost *) request->body->data); - break; + break; case HTTP_REQUEST_BODY_CSTRING: if (request->meth != HTTP_PUT) { @@ -889,13 +880,12 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti HTTP_CURL_OPT(CURLOPT_IOCTLDATA, request); HTTP_CURL_OPT(CURLOPT_READDATA, request); HTTP_CURL_OPT(CURLOPT_INFILESIZE, request->body->size); - break; + break; default: /* shouldn't ever happen */ http_error_ex(HE_ERROR, 0, "Unknown request body type: %d (%s)", request->body->type, request->url); return FAILURE; - break; } } @@ -961,8 +951,7 @@ static size_t http_curl_read_callback(void *data, size_t len, size_t n, void *ct TSRMLS_FETCH_FROM_CTX(request->tsrm_ls); if (request->body) { - switch (request->body->type) - { + switch (request->body->type) { case HTTP_REQUEST_BODY_CSTRING: { size_t out = MIN(len * n, request->body->size - request->body->priv); @@ -972,12 +961,11 @@ static size_t http_curl_read_callback(void *data, size_t len, size_t n, void *ct request->body->priv += out; return out; } + break; } - break; case HTTP_REQUEST_BODY_UPLOADFILE: return php_stream_read((php_stream *) request->body->data, data, len * n); - break; } } return 0; @@ -1023,18 +1011,17 @@ static curlioerr http_curl_ioctl_callback(CURL *ch, curliocmd cmd, void *ctx) } if (request->body) { - switch (request->body->type) - { + switch (request->body->type) { case HTTP_REQUEST_BODY_CSTRING: request->body->priv = 0; return CURLIOE_OK; - break; + break; case HTTP_REQUEST_BODY_UPLOADFILE: if (SUCCESS == php_stream_rewind((php_stream *) request->body->data)) { return CURLIOE_OK; } - break; + break; } } @@ -1047,22 +1034,21 @@ static int http_curl_raw_callback(CURL *ch, curl_infotype type, char *data, size { http_request *request = (http_request *) ctx; - switch (type) - { + switch (type) { case CURLINFO_DATA_IN: if (request->conv.last_type == CURLINFO_HEADER_IN) { phpstr_appends(&request->conv.response, HTTP_CRLF); } case CURLINFO_HEADER_IN: phpstr_append(&request->conv.response, data, length); - break; + break; case CURLINFO_DATA_OUT: if (request->conv.last_type == CURLINFO_HEADER_OUT) { phpstr_appends(&request->conv.request, HTTP_CRLF); } case CURLINFO_HEADER_OUT: phpstr_append(&request->conv.request, data, length); - break; + break; default: #if 0 fprintf(stderr, "## ", type); @@ -1082,7 +1068,7 @@ static int http_curl_raw_callback(CURL *ch, curl_infotype type, char *data, size fprintf(stderr, "\n"); } #endif - break; + break; } if (type) {