Get all headers as string

@param boolean $status_line Whether to return the first status line (IE "HTTP 200 OK")
@param string $br Line breaks (eg. "\n", "\r\n", "<br />")
@return string
772824
public function getHeadersAsString($status_line = true, $br = "\n")
    {
        $str = '';

        if ($status_line) {
            $str = "HTTP/{$this->version} {$this->code} {$this->message}{$br}";
        }

        // Iterate over the headers and stringify them
        foreach ($this->headers as $name => $value)
        {
            if (is_string($value))
                $str .= "{$name}: {$value}{$br}";

            elseif (is_array($value)) {
                foreach ($value as $subval) {
                    $str .= "{$name}: {$subval}{$br}";
                }
            }
        }

        return $str;
    }
174446
function headersToString(headers){
  var lines = [];
  for(var name in headers){
    lines.push(name + ': ' + headers[name]);
  }
  return lines.join('\n');
}
1307096
public static function getRoute($slug, $params = [], $status = self::STATUS_ACTIVE)
    {
        return UrlRule::findOne(['slug' => $slug, 'params' => http_build_query($params), 'status' => $status]);
    }
364928
def status_to_string(dbus_status):
    '''
    
    '''
    status_tuple = (
        dbus_status & 0b000000001, dbus_status & 0b000000010, dbus_status & 0b000000100,
        dbus_status & 0b000001000, dbus_status & 0b000010000, dbus_status & 0b000100000,
        dbus_status & 0b001000000, dbus_status & 0b010000000, dbus_status & 0b100000000
    )

    return [DBUS_STATUS_MAP[status] for status in status_tuple if status]
1001451
public function getTranslatedList($user_id, $status = true)
    {
        $conditions = array(
            'status' => $status,
            'user_id' => $user_id
        );

        $addresses = array();
        foreach ((array) $this->getList($conditions) as $address_id => $address) {
            $addresses[$address_id] = $this->getTranslated($address, true);
        }

        return $addresses;
    }
36289
function renderStatusLine()
    {
        $status = sprintf(
            'HTTP/%s %d %s',
            $this->getVersion(),
            $this->getStatusCode(),
            $this->getStatusReason()
        );

        return trim($status);
    }
967072
protected function getHeaders(string $raw_headers) {
        // Normalize line breaks
        $raw_headers = str_replace("\r\n", "\n", $raw_headers);

        // There will be multiple headers if a 301 was followed
        // or a proxy was followed, etc
        $header_collection = explode("\n\n", trim($raw_headers));
        // We just want the last response (at the end)
        $raw_header = array_pop($header_collection);

        $header_components = explode("\n", $raw_header);
        $result = array();
        $http_status = 0;
        foreach ($header_components as $line) {
            if (strpos($line, ': ') === false) {
                $http_status = $this->getHttpStatus($line);
            } else {
                list($key, $value) = explode(': ', $line, 2);
                $result[$key] = $value;
            }
        }

        return array($http_status, $result);
    }
243838
def status_line(self):
        
        if not self.phrase:
            self.phrase = HttpStatus(self.status_code).phrase
        return "{} {} {}".format("HTTP/1.1", self.status_code, self.phrase)
1007643
protected function readResponseHeader(&$error_code, &$error_string)
  { 
    PHPCrawlerBenchmark::reset("server_response_time");
    PHPCrawlerBenchmark::start("server_response_time");
    
    $status = socket_get_status($this->socket);
    $source_read = "";
    $header = "";
    $server_responded = false;
    
    while ($status["eof"] == false)
    {
      socket_set_timeout($this->socket, $this->socketReadTimeout);
      
      // Read line from socket
      $line_read = fgets($this->socket, 1024);
      
      // Server responded
      if ($server_responded == false)
      {
        $server_responded = true;
        $this->server_response_time = PHPCrawlerBenchmark::stop("server_response_time");
    
        // Determinate socket prefill size
        $status = socket_get_status($this->socket);
        $this->socket_prefill_size = $status["unread_bytes"];
        
        // Start data-transfer-time bechmark
        PHPCrawlerBenchmark::reset("data_transfer_time");
        PHPCrawlerBenchmark::start("data_transfer_time");
      }
      
      $source_read .= $line_read;
      
      $this->global_traffic_count += strlen($line_read);
      
      $status = socket_get_status($this->socket);
      
      // Socket timed out
      if ($status["timed_out"] == true)
      {
        $error_code = PHPCrawlerRequestErrors::ERROR_SOCKET_TIMEOUT;
        $error_string = "Socket-stream timed out (timeout set to ".$this->socketReadTimeout." sec).";
        return $header;
      }
      
      // No "HTTP" at beginnig of response
      if (strtolower(substr($source_read, 0, 4)) != "http")
      {
        $error_code = PHPCrawlerRequestErrors::ERROR_NO_HTTP_HEADER;
        $error_string = "HTTP-protocol error.";
        return $header;
      }
      
      // Header found and read (2 newlines) -> stop
      if (substr($source_read, -4, 4) == "\r\n\r\n" || substr($source_read, -2, 2) == "\n\n")
      {
        $header = substr($source_read, 0, strlen($source_read)-2);
        break;
      }
    }
    
    // Stop data-transfer-time bechmark
    PHPCrawlerBenchmark::stop("data_transfer_time");
    
    // Header was found
    if ($header != "")
    {
      // Search for links (redirects) in the header
      $this->LinkFinder->processHTTPHeader($header);
      $this->header_bytes_received = strlen($header);
      return $header;
    }
        
    // No header found
    if ($header == "")
    {
      $this->server_response_time = null;
      $error_code = PHPCrawlerRequestErrors::ERROR_NO_HTTP_HEADER;
      $error_string = "Host doesn't respond with a HTTP-header.";
      return null;
    }
  }
447769
public function toString()
    {
        $response = Parser\ResponseParser::buildStatusLine($this) . Http::NEW_LINE;
        $headers  = Parser\ResponseParser::buildHeaderFromMessage($this);

        foreach ($headers as $header) {
            $response.= $header . Http::NEW_LINE;
        }

        $response.= Http::NEW_LINE;
        $response.= (string) $this->getBody();

        return $response;
    }
1163420
public function getStatus($raw_output = true)
    {
        if ($raw_output) {
            return $this->_status;
        }
        return self::$_statusToString[$this->_status];
    }
481455
private function getHeaders($str) {
    $str = explode(self::LE . self::LE, $str);
    $str = reset($str);
    $str = explode(self::LE, $str);
    $new = array();
    $s = 1;
    foreach ($str as $line) {
      $pos = strpos($line, ': ');
      if ($pos !== false) {
        $key = strtolower(substr($line, 0, $pos));
        if (!isset($new[$key])) {
          $new[$key] = preg_replace('/\s+/', ' ', trim(substr($line, $pos+1)));
        }
        else {
          $new[$key.'-'.$s] = preg_replace('/\s+/', ' ', trim(substr($line, $pos+1)));
          $s++;
        }
      }
      else {
        $new['status'] = $line; # HTTP/1.1 200 OK
      }
    }
    return $new;
  }
1209991
static String getSingleHeader(HTTPResponse resp, String headerName) {
    return Iterables.getOnlyElement(getHeaders(resp, headerName)).getValue();
  }
1275528
public static function headers()
	{
		// disabled ?
		//
		if (!self::_debug())
		{
			return false;
		}

		if (!function_exists('getallheaders'))
		{
			function getallheaders()
			{
				$headers = array ();
				foreach ($_SERVER as $name => $value)
				{
					if (substr($name, 0, 5) == 'HTTP_')
					{
						$key = str_replace(
							' ',
							'-',
							ucwords(strtolower(
								str_replace('_', ' ', substr($name, 5))
								))
							);
						$headers[$key] = $value;
					}
				}
				return $headers;
			}
		}

		// render it
		//
		?>
<div class="krumo-title">
This is a list of all HTTP request headers.
</div>
		<?php
		return self::dump(getallheaders());
	}
652732
protected function _getBrowserHeaders()
    {
        $sHeaders = '';
        $aHeaders = apache_request_headers();

        foreach ( $aHeaders as $sHeader => $sValue ) {
            $sHeaders .= " $sHeader: $sValue\n";
        }

        return base64_encode( $sHeaders );
    }
908462
public function success($str = 'Success', $sub_header = null)
    {
        // by using this hook you can overwrite default behavior of this method
        if ($this->hookHasCallbacks('displaySuccess')) {
            return $this->hook('displaySuccess', [$str, $sub_header]);
        }

        /* below code works, but pollutes output with bad id=xx
        $success = new Message([$str, 'id'=>false, 'type'=>'success', 'icon'=>'check']);
        $success->app = $this->app;
        $success->init();
        $success->text->addParagraph($sub_header);
         */
        $success = $this->app->loadTemplate($this->successTemplate);
        $success['header'] = $str;

        if ($sub_header) {
            $success['message'] = $sub_header;
        } else {
            $success->del('p');
        }

        $js = $this->js()
            ->html($success->render());

        return $js;
    }
567214
public static function getString ($status = FALSE, $tagStart = NULL, $tagEnd = "\n")
	{
		
		// Get messages
		
		$arr	= self::get ($status);
		
		// Set message string
		
		$str	= '';
		
		foreach ($arr as $msg)
		{
			$str	.= $tagStart . $msg . $tagEnd;
		}
		
		// Return message
		
		return $str;
		
	}