Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / response / PhabricatorVCSResponse.php
blob544dc1f0ff2706d63f4a8677de06860eeecb90b9
1 <?php
3 /**
4 * In Git, there appears to be no way to send a message which will be output
5 * by `git clone http://...`, although the response code is visible. We send
6 * the message in a header which is visible with "GIT_CURL_VERBOSE" if you
7 * know where to look.
9 * In Mercurial, the HTTP status response message is printed to the console, so
10 * we send human-readable text there.
12 * In Subversion, we can get it to print a custom message if we send an
13 * invalid/unknown response code, although the output is ugly and difficult
14 * to read. For known codes like 404, it prints a canned message.
16 * All VCS binaries ignore the response body; we include it only for
17 * completeness.
19 final class PhabricatorVCSResponse extends AphrontResponse {
21 private $code;
22 private $message;
24 public function __construct($code, $message) {
25 $this->code = $code;
27 $message = head(phutil_split_lines($message));
28 $this->message = $message;
31 public function getMessage() {
32 return $this->message;
35 public function buildResponseString() {
36 return $this->code.' '.$this->message;
39 public function getHeaders() {
40 $headers = array();
42 if ($this->getHTTPResponseCode() == 401) {
43 $headers[] = array(
44 'WWW-Authenticate',
45 'Basic realm="Phabricator Repositories"',
49 $message = $this->getMessage();
50 if (strlen($message)) {
51 foreach (phutil_split_lines($message, false) as $line) {
52 $headers[] = array(
53 'X-Phabricator-Message',
54 $line,
59 return $headers;
62 public function getCacheHeaders() {
63 return array();
66 public function getHTTPResponseCode() {
67 return $this->code;
70 public function getHTTPResponseMessage() {
71 return $this->message;