@@ -86,6 +86,8 @@ function Qiniu_ResponseError($resp) // => $error
86
86
}
87
87
}
88
88
}
89
+ $ err ->Reqid = $ reqId ;
90
+ $ err ->Details = $ details ;
89
91
return $ err ;
90
92
}
91
93
@@ -114,6 +116,8 @@ function Qiniu_Client_do($req) // => ($resp, $error)
114
116
CURLOPT_RETURNTRANSFER => true ,
115
117
CURLOPT_SSL_VERIFYPEER => false ,
116
118
CURLOPT_SSL_VERIFYHOST => false ,
119
+ CURLOPT_HEADER => true ,
120
+ CURLOPT_NOBODY => false ,
117
121
CURLOPT_CUSTOMREQUEST => 'POST ' ,
118
122
CURLOPT_URL => $ url ['path ' ]
119
123
);
@@ -141,11 +145,37 @@ function Qiniu_Client_do($req) // => ($resp, $error)
141
145
$ code = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
142
146
$ contentType = curl_getinfo ($ ch , CURLINFO_CONTENT_TYPE );
143
147
curl_close ($ ch );
144
- $ resp = new Qiniu_Response ($ code , $ result );
148
+
149
+ $ responseArray = explode ("\r\n\r\n" , $ result );
150
+ $ responseArraySize = sizeof ($ responseArray );
151
+ $ respHeader = $ responseArray [$ responseArraySize -2 ];
152
+ $ respBody = $ responseArray [$ responseArraySize -1 ];
153
+
154
+ list ($ reqid , $ xLog ) = getReqInfo ($ respHeader );
155
+
156
+ $ resp = new Qiniu_Response ($ code , $ respBody );
145
157
$ resp ->Header ['Content-Type ' ] = $ contentType ;
158
+ $ resp ->Header ["X-Reqid " ] = $ reqid ;
146
159
return array ($ resp , null );
147
160
}
148
161
162
+ function getReqInfo ($ headerContent ) {
163
+ $ headers = explode ("\r\n" , $ headerContent );
164
+ $ reqid = null ;
165
+ $ xLog = null ;
166
+ foreach ($ headers as $ header ) {
167
+ $ header = trim ($ header );
168
+ if (strpos ($ header , 'X-Reqid ' ) !== false ) {
169
+ list ($ k , $ v ) = explode (': ' , $ header );
170
+ $ reqid = trim ($ v );
171
+ } elseif (strpos ($ header , 'X-Log ' ) !== false ) {
172
+ list ($ k , $ v ) = explode (': ' , $ header );
173
+ $ xLog = trim ($ v );
174
+ }
175
+ }
176
+ return array ($ reqid , $ xLog );
177
+ }
178
+
149
179
class Qiniu_HttpClient
150
180
{
151
181
public function RoundTrip ($ req ) // => ($resp, $error)
0 commit comments