1: <?php
2:
3: 4: 5:
6: class RESTian_Php_Curl_Http_Agent extends RESTian_Http_Agent_Base {
7: 8: 9: 10: 11: 12: 13:
14: function make_request( $request, $response ) {
15:
16: $ch = curl_init();
17:
18: curl_setopt_array(
19: $ch, array(
20: CURLOPT_URL => $request->get_url(),
21: CURLOPT_USERAGENT => $request->client->get_user_agent(),
22: CURLOPT_HTTPHEADER => $request->get_curl_headers(),
23: CURLOPT_POST => false,
24: CURLOPT_HEADER => false,
25: CURLOPT_TIMEOUT => '30',
26: CURLOPT_RETURNTRANSFER => true,
27: CURLOPT_SSL_VERIFYPEER => $request->sslverify,
28: CURLOPT_SSL_VERIFYHOST => ( true === $request->sslverify ) ? 2 : false,
29: ));
30: if ( ! $request->omit_body ) {
31: $response->body = trim( curl_exec( $ch ) );
32: }
33:
34: $info = curl_getinfo($ch);
35: $response->status_code = $info['http_code'];
36:
37: if ( 0 != curl_errno( $ch ) )
38: $response->set_http_error( curl_errno( $ch ), curl_error( $ch ) );
39:
40: if ( ! $request->omit_result ) {
41: $response->result = (object)array(
42: 'info' => $info,
43: 'version' => curl_version(),
44: 'error' => curl_error( $ch ),
45: 'errno' => curl_errno( $ch ),
46: );
47: }
48: curl_close($ch);
49:
50: return $response;
51: }
52:
53: }
54:
55: