2
2
namespace Qiniu \Http ;
3
3
4
4
use Qiniu \Config ;
5
- use Qiniu \Http \Request ;
6
- use Qiniu \Http \Response ;
7
5
8
6
final class Client
9
7
{
10
- public static function get ($ url , array $ headers = array ())
8
+ /**
9
+ * @param $url
10
+ * @param array $headers
11
+ * @param RequestOptions $opt
12
+ * @return Response
13
+ */
14
+ public static function get ($ url , array $ headers = array (), $ opt = null )
11
15
{
12
- $ request = new Request ('GET ' , $ url , $ headers );
16
+ $ request = new Request ('GET ' , $ url , $ headers, null , $ opt );
13
17
return self ::sendRequest ($ request );
14
18
}
15
19
16
- public static function delete ($ url , array $ headers = array ())
20
+ /**
21
+ * @param $url
22
+ * @param array $headers
23
+ * @param array $opt detail see {@see Request::$opt}
24
+ * @return Response
25
+ */
26
+ public static function delete ($ url , array $ headers = array (), $ opt = null )
17
27
{
18
- $ request = new Request ('DELETE ' , $ url , $ headers );
28
+ $ request = new Request ('DELETE ' , $ url , $ headers, null , $ opt );
19
29
return self ::sendRequest ($ request );
20
30
}
21
31
22
- public static function post ($ url , $ body , array $ headers = array ())
32
+ /**
33
+ * @param $url
34
+ * @param $body
35
+ * @param array $headers
36
+ * @param RequestOptions $opt
37
+ * @return Response
38
+ */
39
+ public static function post ($ url , $ body , array $ headers = array (), $ opt = null )
23
40
{
24
- $ request = new Request ('POST ' , $ url , $ headers , $ body );
41
+ $ request = new Request ('POST ' , $ url , $ headers , $ body, $ opt );
25
42
return self ::sendRequest ($ request );
26
43
}
27
44
28
- public static function PUT ($ url , $ body , array $ headers = array ())
45
+ /**
46
+ * @param $url
47
+ * @param $body
48
+ * @param array $headers
49
+ * @param RequestOptions $opt
50
+ * @return Response
51
+ */
52
+ public static function PUT ($ url , $ body , array $ headers = array (), $ opt = null )
29
53
{
30
- $ request = new Request ('PUT ' , $ url , $ headers , $ body );
54
+ $ request = new Request ('PUT ' , $ url , $ headers , $ body, $ opt );
31
55
return self ::sendRequest ($ request );
32
56
}
33
57
58
+ /**
59
+ * @param $url
60
+ * @param array $fields
61
+ * @param string $name
62
+ * @param string $fileName
63
+ * @param $fileBody
64
+ * @param null $mimeType
65
+ * @param array $headers
66
+ * @param RequestOptions $opt
67
+ * @return Response
68
+ */
34
69
public static function multipartPost (
35
70
$ url ,
36
71
$ fields ,
37
72
$ name ,
38
73
$ fileName ,
39
74
$ fileBody ,
40
75
$ mimeType = null ,
41
- array $ headers = array ()
76
+ $ headers = array (),
77
+ $ opt = null
42
78
) {
43
79
$ data = array ();
44
80
$ mimeBoundary = md5 (microtime ());
@@ -62,10 +98,9 @@ public static function multipartPost(
62
98
array_push ($ data , '' );
63
99
64
100
$ body = implode ("\r\n" , $ data );
65
- // var_dump($data);exit;
66
101
$ contentType = 'multipart/form-data; boundary= ' . $ mimeBoundary ;
67
102
$ headers ['Content-Type ' ] = $ contentType ;
68
- $ request = new Request ('POST ' , $ url , $ headers , $ body );
103
+ $ request = new Request ('POST ' , $ url , $ headers , $ body, $ opt );
69
104
return self ::sendRequest ($ request );
70
105
}
71
106
@@ -84,6 +119,10 @@ private static function userAgent()
84
119
return $ ua ;
85
120
}
86
121
122
+ /**
123
+ * @param Request $request
124
+ * @return Response
125
+ */
87
126
public static function sendRequest ($ request )
88
127
{
89
128
$ t1 = microtime (true );
@@ -98,6 +137,9 @@ public static function sendRequest($request)
98
137
CURLOPT_CUSTOMREQUEST => $ request ->method ,
99
138
CURLOPT_URL => $ request ->url ,
100
139
);
140
+ foreach ($ request ->opt ->getCurlOpt () as $ k => $ v ) {
141
+ $ options [$ k ] = $ v ;
142
+ }
101
143
// Handle open_basedir & safe mode
102
144
if (!ini_get ('safe_mode ' ) && !ini_get ('open_basedir ' )) {
103
145
$ options [CURLOPT_FOLLOWLOCATION ] = true ;
0 commit comments