Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加reqid、xlog信息 #70

Merged
merged 2 commits into from
Apr 15, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion qiniu/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ function Qiniu_ResponseError($resp) // => $error
}
}
}
$err->Reqid = $reqId;
$err->Details = $details;
return $err;
}

Expand Down Expand Up @@ -114,6 +116,8 @@ function Qiniu_Client_do($req) // => ($resp, $error)
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HEADER => true,
CURLOPT_NOBODY => false,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_URL => $url['path']
);
Expand Down Expand Up @@ -141,11 +145,38 @@ function Qiniu_Client_do($req) // => ($resp, $error)
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);
$resp = new Qiniu_Response($code, $result);

$responseArray = explode("\r\n\r\n", $result);
$responseArraySize = sizeof($responseArray);
$respHeader = $responseArray[$responseArraySize-2];
$respBody = $responseArray[$responseArraySize-1];

list($reqid, $xLog) = getReqInfo($respHeader);

$resp = new Qiniu_Response($code, $respBody);
$resp->Header['Content-Type'] = $contentType;
$resp->Header["X-Reqid"] = $reqid;
$resp->Header["X-Log"] = $xLog;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xlog 暂时不要加,等服务器端的xlog缩写完成后再加入

return array($resp, null);
}

function getReqInfo($headerContent) {
$headers = explode("\r\n", $headerContent);
$reqid = null;
$xLog = null;
foreach($headers as $header) {
$header = trim($header);
if(strpos($header, 'X-Reqid') !== false) {
list($k, $v) = explode(':', $header);
$reqid = trim($v);
} elseif(strpos($header, 'X-Log') !== false) {
list($k, $v) = explode(':', $header);
$xLog = trim($v);
}
}
return array($reqid, $xLog);
}

class Qiniu_HttpClient
{
public function RoundTrip($req) // => ($resp, $error)
Expand Down
10 changes: 10 additions & 0 deletions tests/IoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ public function setUp()
$this->bucket = getenv("QINIU_BUCKET_NAME");
}

public function testReqid()
{
$key = 'testReqid' . getTid();
list($ret, $err) = Qiniu_PutFile("", $key, __file__, null);
$this->assertNotNull($err);
$this->assertNotNull($err->Reqid);
$this->assertNotNull($err->Details);
var_dump($err);
}

public function testPutFile()
{
$key = 'testPutFile' . getTid();
Expand Down