@@ -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,38 @@ 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 ;
159
+ $ resp ->Header ["X-Log " ] = $ xLog ;
146
160
return array ($ resp , null );
147
161
}
148
162
163
+ function getReqInfo ($ headerContent ) {
164
+ $ headers = explode ("\r\n" , $ headerContent );
165
+ $ reqid = null ;
166
+ $ xLog = null ;
167
+ foreach ($ headers as $ header ) {
168
+ $ header = trim ($ header );
169
+ if (strpos ($ header , 'X-Reqid ' ) !== false ) {
170
+ list ($ k , $ v ) = explode (': ' , $ header );
171
+ $ reqid = trim ($ v );
172
+ } elseif (strpos ($ header , 'X-Log ' ) !== false ) {
173
+ list ($ k , $ v ) = explode (': ' , $ header );
174
+ $ xLog = trim ($ v );
175
+ }
176
+ }
177
+ return array ($ reqid , $ xLog );
178
+ }
179
+
149
180
class Qiniu_HttpClient
150
181
{
151
182
public function RoundTrip ($ req ) // => ($resp, $error)
0 commit comments