Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/MWP/Http
File: Response.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[2] Fix | Delete
*
[3] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[4] Fix | Delete
*
[5] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[6] Fix | Delete
* file that was distributed with this source code.
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
class MWP_Http_Response implements MWP_Http_ResponseInterface
[10] Fix | Delete
{
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Status codes translation table.
[14] Fix | Delete
*
[15] Fix | Delete
* The list of codes is complete according to the
[16] Fix | Delete
* {@link http://www.iana.org/assignments/http-status-codes/ Hypertext Transfer Protocol (HTTP) Status Code Registry}
[17] Fix | Delete
* (last updated 2012-02-13).
[18] Fix | Delete
*
[19] Fix | Delete
* Unless otherwise noted, the status code is defined in RFC2616.
[20] Fix | Delete
*
[21] Fix | Delete
* @var array
[22] Fix | Delete
*/
[23] Fix | Delete
public static $statusTexts = array(
[24] Fix | Delete
100 => 'Continue',
[25] Fix | Delete
101 => 'Switching Protocols',
[26] Fix | Delete
102 => 'Processing', // RFC2518
[27] Fix | Delete
200 => 'OK',
[28] Fix | Delete
201 => 'Created',
[29] Fix | Delete
202 => 'Accepted',
[30] Fix | Delete
203 => 'Non-Authoritative Information',
[31] Fix | Delete
204 => 'No Content',
[32] Fix | Delete
205 => 'Reset Content',
[33] Fix | Delete
206 => 'Partial Content',
[34] Fix | Delete
207 => 'Multi-Status', // RFC4918
[35] Fix | Delete
208 => 'Already Reported', // RFC5842
[36] Fix | Delete
226 => 'IM Used', // RFC3229
[37] Fix | Delete
300 => 'Multiple Choices',
[38] Fix | Delete
301 => 'Moved Permanently',
[39] Fix | Delete
302 => 'Found',
[40] Fix | Delete
303 => 'See Other',
[41] Fix | Delete
304 => 'Not Modified',
[42] Fix | Delete
305 => 'Use Proxy',
[43] Fix | Delete
306 => 'Reserved',
[44] Fix | Delete
307 => 'Temporary Redirect',
[45] Fix | Delete
308 => 'Permanent Redirect', // RFC7238
[46] Fix | Delete
400 => 'Bad Request',
[47] Fix | Delete
401 => 'Unauthorized',
[48] Fix | Delete
402 => 'Payment Required',
[49] Fix | Delete
403 => 'Forbidden',
[50] Fix | Delete
404 => 'Not Found',
[51] Fix | Delete
405 => 'Method Not Allowed',
[52] Fix | Delete
406 => 'Not Acceptable',
[53] Fix | Delete
407 => 'Proxy Authentication Required',
[54] Fix | Delete
408 => 'Request Timeout',
[55] Fix | Delete
409 => 'Conflict',
[56] Fix | Delete
410 => 'Gone',
[57] Fix | Delete
411 => 'Length Required',
[58] Fix | Delete
412 => 'Precondition Failed',
[59] Fix | Delete
413 => 'Request Entity Too Large',
[60] Fix | Delete
414 => 'Request-URI Too Long',
[61] Fix | Delete
415 => 'Unsupported Media Type',
[62] Fix | Delete
416 => 'Requested Range Not Satisfiable',
[63] Fix | Delete
417 => 'Expectation Failed',
[64] Fix | Delete
418 => 'I\'m a teapot', // RFC2324
[65] Fix | Delete
422 => 'Unprocessable Entity', // RFC4918
[66] Fix | Delete
423 => 'Locked', // RFC4918
[67] Fix | Delete
424 => 'Failed Dependency', // RFC4918
[68] Fix | Delete
425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817
[69] Fix | Delete
426 => 'Upgrade Required', // RFC2817
[70] Fix | Delete
428 => 'Precondition Required', // RFC6585
[71] Fix | Delete
429 => 'Too Many Requests', // RFC6585
[72] Fix | Delete
431 => 'Request Header Fields Too Large', // RFC6585
[73] Fix | Delete
500 => 'Internal Server Error',
[74] Fix | Delete
501 => 'Not Implemented',
[75] Fix | Delete
502 => 'Bad Gateway',
[76] Fix | Delete
503 => 'Service Unavailable',
[77] Fix | Delete
504 => 'Gateway Timeout',
[78] Fix | Delete
505 => 'HTTP Version Not Supported',
[79] Fix | Delete
506 => 'Variant Also Negotiates (Experimental)', // RFC2295
[80] Fix | Delete
507 => 'Insufficient Storage', // RFC4918
[81] Fix | Delete
508 => 'Loop Detected', // RFC5842
[82] Fix | Delete
510 => 'Not Extended', // RFC2774
[83] Fix | Delete
511 => 'Network Authentication Required', // RFC6585
[84] Fix | Delete
);
[85] Fix | Delete
[86] Fix | Delete
protected $content;
[87] Fix | Delete
[88] Fix | Delete
protected $statusCode;
[89] Fix | Delete
[90] Fix | Delete
protected $headers = array();
[91] Fix | Delete
[92] Fix | Delete
public function __construct($content, $statusCode = 200, array $headers = array())
[93] Fix | Delete
{
[94] Fix | Delete
$this->content = $content;
[95] Fix | Delete
$this->statusCode = $statusCode;
[96] Fix | Delete
$this->headers = array_change_key_case($headers, CASE_LOWER);
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
public function getContentAsString()
[100] Fix | Delete
{
[101] Fix | Delete
return $this->content;
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* @param mixed $content
[106] Fix | Delete
*
[107] Fix | Delete
* @return mixed
[108] Fix | Delete
*/
[109] Fix | Delete
public function setContent($content)
[110] Fix | Delete
{
[111] Fix | Delete
$this->content = $content;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* @return mixed
[116] Fix | Delete
*/
[117] Fix | Delete
public function getContent()
[118] Fix | Delete
{
[119] Fix | Delete
return $this->content;
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* @return void
[124] Fix | Delete
*/
[125] Fix | Delete
public function send()
[126] Fix | Delete
{
[127] Fix | Delete
$this->sendHeaders();
[128] Fix | Delete
[129] Fix | Delete
// Some plugins leave open buffers and when it happens the returned output is blank
[130] Fix | Delete
$bufferCount = count(ob_list_handlers());
[131] Fix | Delete
while ($bufferCount) {
[132] Fix | Delete
ob_end_clean();
[133] Fix | Delete
--$bufferCount;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
if ($this instanceof MWP_Http_StreamingResponseInterface) {
[137] Fix | Delete
$stream = $this->createResponseStream();
[138] Fix | Delete
[139] Fix | Delete
ini_set('display_errors', false);
[140] Fix | Delete
[141] Fix | Delete
while (!$stream->eof()) {
[142] Fix | Delete
print $stream->read(1048576);
[143] Fix | Delete
}
[144] Fix | Delete
} else {
[145] Fix | Delete
print $this->getContentAsString();
[146] Fix | Delete
}
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
protected function sendHeaders()
[150] Fix | Delete
{
[151] Fix | Delete
if (headers_sent()) {
[152] Fix | Delete
return;
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
if (function_exists('header_remove')) {
[156] Fix | Delete
/** @handled function */
[157] Fix | Delete
header_remove('Location');
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
$protocol = 'HTTP/1.1';
[161] Fix | Delete
if (isset($_SERVER['SERVER_PROTOCOL']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.0') {
[162] Fix | Delete
$protocol = 'HTTP/1.0';
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
if (isset(self::$statusTexts[$this->statusCode])) {
[166] Fix | Delete
header(sprintf('%s %s %s', $protocol, $this->statusCode, self::$statusTexts[$this->statusCode]), true, $this->statusCode);
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
foreach ($this->headers as $headerName => $headerValue) {
[170] Fix | Delete
header(sprintf('%s: %s', $headerName, $headerValue), false, $this->statusCode);
[171] Fix | Delete
}
[172] Fix | Delete
}
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function