bool TestExtCurl::test_curl_close() { Variant c = f_curl_init(String(get_request_uri())); f_curl_setopt(c.toResource(), k_CURLOPT_RETURNTRANSFER, true); f_curl_exec(c.toResource()); f_curl_close(c.toResource()); return Count(true); }
Variant f_get_headers(CStrRef url, int format /* = 0 */) { Variant c = f_curl_init(); f_curl_setopt(c, k_CURLOPT_URL, url); f_curl_setopt(c, k_CURLOPT_RETURNTRANSFER, true); f_curl_setopt(c, k_CURLOPT_HEADER, 1); Variant res = f_curl_exec(c); if (same(res, false)) { return false; } String response = res.toString(); int pos = response.find("\r\n\r\n"); if (pos != String::npos) { response = response.substr(0, pos); } Array ret = f_explode("\r\n", response); if (!format) { return ret; } Array assoc; for (ArrayIter iter(ret); iter; ++iter) { Array tokens = f_explode(": ", iter.second(), 2); if (tokens.size() == 2) { assoc.set(tokens[0], tokens[1]); } else { assoc.append(iter.second()); } } return assoc; }
bool TestDebugger::getResponse(const string& path, string& result, int port /* = -1 */, const string& host /* = "" */) { String server = "http://"; if (host.empty()) { server += f_php_uname("n"); } else { server += host; } server += ":" + boost::lexical_cast<string>(port > 0 ? port : m_serverPort); server += "/" + path; printf("\n Getting URL '%s'...\n", server.get()->data()); Variant c = f_curl_init(); f_curl_setopt(c, k_CURLOPT_URL, server); f_curl_setopt(c, k_CURLOPT_RETURNTRANSFER, true); f_curl_setopt(c, CURLOPT_TIMEOUT, 120); Variant res = f_curl_exec(c); if (same(res, false)) { printf(" Request failed\n"); return false; } result = (std::string) res.toString(); printf(" Request succeeded, returning '%s'\n", result.c_str()); return true; }
bool TestExtCurl::test_curl_errno() { Variant c = f_curl_init("http://www.thereisnosuchanurl"); f_curl_setopt(c.toResource(), k_CURLOPT_RETURNTRANSFER, true); f_curl_exec(c.toResource()); Variant err = f_curl_errno(c.toResource()); VS(err, k_CURLE_COULDNT_RESOLVE_HOST); return Count(true); }
bool TestExtCurl::test_curl_setopt() { Variant c = f_curl_init(); f_curl_setopt(c, k_CURLOPT_URL, String(get_request_uri())); f_curl_setopt(c, k_CURLOPT_RETURNTRANSFER, true); Variant res = f_curl_exec(c); VS(res, "OK"); return Count(true); }
bool TestExtCurl::test_curl_exec() { { Variant c = f_curl_init(String(get_request_uri())); f_curl_setopt(c.toResource(), k_CURLOPT_RETURNTRANSFER, true); Variant res = f_curl_exec(c.toResource()); VS(res, "OK"); } { Variant c = f_curl_init(String(get_request_uri())); f_curl_setopt(c.toResource(), k_CURLOPT_WRITEFUNCTION, "curl_write_func"); f_ob_start(); f_curl_exec(c.toResource()); String res = f_ob_get_contents(); VS(res, "curl_write_func called with OK"); f_ob_end_clean(); } return Count(true); }
bool TestExtCurl::test_curl_error() { Variant c = f_curl_init("http://www.thereisnosuchanurl"); f_curl_setopt(c.toResource(), k_CURLOPT_RETURNTRANSFER, true); f_curl_exec(c.toResource()); Variant err = f_curl_error(c.toResource()); VERIFY(equal(err, String("Couldn't resolve host 'www.thereisnosuchanurl'")) || equal(err, String("Could not resolve host: www.thereisnosuchanurl" " (Domain name not found)"))); return Count(true); }
bool TestExtCurl::test_curl_getinfo() { Variant c = f_curl_init(String(get_request_uri())); f_curl_setopt(c.toResource(), k_CURLOPT_RETURNTRANSFER, true); f_curl_exec(c.toResource()); Variant ret = f_curl_getinfo(c.toResource()); VS(ret[s_url], String(get_request_uri())); ret = f_curl_getinfo(c.toResource(), k_CURLINFO_EFFECTIVE_URL); VS(ret, String(get_request_uri())); return Count(true); }
bool TestExtCurl::test_curl_setopt_array() { Variant c = f_curl_init(); f_curl_setopt_array (c.toResource(), make_map_array(k_CURLOPT_URL, String(get_request_uri()), k_CURLOPT_RETURNTRANSFER, true)); Variant res = f_curl_exec(c.toResource()); VS(res, "OK"); return Count(true); }
bool TestExtCurl::test_curl_copy_handle() { Variant c = f_curl_init(); f_curl_setopt(c.toResource(), k_CURLOPT_URL, String(get_request_uri())); f_curl_setopt(c.toResource(), k_CURLOPT_RETURNTRANSFER, true); Variant cpy = f_curl_copy_handle(c.toResource()); f_curl_close(c.toResource()); // to test cpy is still working fine Variant res = f_curl_exec(cpy.toResource()); if (res.toString() != s_OK) { // XXX: t1782098 return CountSkip(); } return Count(true); }