mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-07 20:38:32 +01:00
3a74701555
Summary: Ref T13590. Currently, when you encounter a HTTP error in Git, there is no apparent way to make the client show any additional useful information. In particular, the response body is ignored. We can partially get around this by putting the information in an "X-Phabricator-Message: ..." HTTP header, which is visible with "GIT_CURL_VERBOSE=1 git ...". Users won't normally know to look here, but it's still better than nothing. Test Plan: - Ran "GIT_CURL_VERBOSE=1 git fetch" against a Phabricator HTTP URI that returned a HTTP/500 error. - Before: no clue what happened on the client. - After: client shows useful message in the "X-Phabricator-Message" header in debug output. Maniphest Tasks: T13590 Differential Revision: https://secure.phabricator.com/D21523
74 lines
1.8 KiB
PHP
74 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* In Git, there appears to be no way to send a message which will be output
|
|
* by `git clone http://...`, although the response code is visible. We send
|
|
* the message in a header which is visible with "GIT_CURL_VERBOSE" if you
|
|
* know where to look.
|
|
*
|
|
* In Mercurial, the HTTP status response message is printed to the console, so
|
|
* we send human-readable text there.
|
|
*
|
|
* In Subversion, we can get it to print a custom message if we send an
|
|
* invalid/unknown response code, although the output is ugly and difficult
|
|
* to read. For known codes like 404, it prints a canned message.
|
|
*
|
|
* All VCS binaries ignore the response body; we include it only for
|
|
* completeness.
|
|
*/
|
|
final class PhabricatorVCSResponse extends AphrontResponse {
|
|
|
|
private $code;
|
|
private $message;
|
|
|
|
public function __construct($code, $message) {
|
|
$this->code = $code;
|
|
|
|
$message = head(phutil_split_lines($message));
|
|
$this->message = $message;
|
|
}
|
|
|
|
public function getMessage() {
|
|
return $this->message;
|
|
}
|
|
|
|
public function buildResponseString() {
|
|
return $this->code.' '.$this->message;
|
|
}
|
|
|
|
public function getHeaders() {
|
|
$headers = array();
|
|
|
|
if ($this->getHTTPResponseCode() == 401) {
|
|
$headers[] = array(
|
|
'WWW-Authenticate',
|
|
'Basic realm="Phabricator Repositories"',
|
|
);
|
|
}
|
|
|
|
$message = $this->getMessage();
|
|
if (strlen($message)) {
|
|
foreach (phutil_split_lines($message, false) as $line) {
|
|
$headers[] = array(
|
|
'X-Phabricator-Message',
|
|
$line,
|
|
);
|
|
}
|
|
}
|
|
|
|
return $headers;
|
|
}
|
|
|
|
public function getCacheHeaders() {
|
|
return array();
|
|
}
|
|
|
|
public function getHTTPResponseCode() {
|
|
return $this->code;
|
|
}
|
|
|
|
public function getHTTPResponseMessage() {
|
|
return $this->message;
|
|
}
|
|
|
|
}
|