Send HTTP response headers and body

@return \Slim\Interfaces\Http\Response Self
@api
424768
public function send()
    {
        // Send headers
        if (headers_sent() === false) {
            if (strpos(PHP_SAPI, 'cgi') === 0) {
                header(sprintf('Status: %s', $this->getReasonPhrase()));
            } else {
                header(sprintf('%s %s', $this->getProtocolVersion(), $this->getReasonPhrase()));
            }

            foreach ($this->headers as $name => $value) {
                foreach ($value as $hVal) {
                    header("$name: $hVal", false);
                }
            }
        }

        // Send body
        $this->body->seek(0);
        while ($this->body->feof() === false) {
            echo $this->body->read(1024);
        }

        return $this;
    }
692888
public function send()
    {
        $data = $this->getData();
        $reflect = new ReflectionClass($this);

        $this->trigger('before' . $reflect->getShortName(), new Event($this));
        
        $response = $this->sendData($data);

        $this->trigger('after' . $reflect->getShortName(), new Event($this));

        return $response;
    }
394324
public function send()
    {
        // Set response code
        http_response_code($this->status);

        // Set content-type
        header("Content-Type: {$this->contentType}");

        // Set headers
        foreach ($this->headers as $header) {
            header("{$header[0]}: {$header[1]}", $header[2]);
        }

        // Print the content
        print($this->body);
    }
1308898
public function send() {

		//Set default status
		$this -> response -> setStatus([

			'code' 		=> 0,
		    'protocol' 	=> '',
		    'status' 	=> '',
		    'text' 		=> ''
		]);

		$curl = curl_init();

		curl_setopt_array($curl, $this -> createOptions());

		$response = curl_exec($curl);

		if(false !== $response) {

			$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
			$headers 	 = substr($response, 0, $header_size);
			$headers 	 = $this -> parseHeaders($headers);
			$body 		 = substr($response, $header_size);
			$json 		 = @json_decode($body, true);

			$this -> response -> setHeaders($headers['headers']);
			$this -> response -> setBody($body);
			$this -> response -> setStatus($headers['status']);
			$this -> response -> setCookies($this -> parseCookies($response));
			$this -> response -> setResponse($response);

			if(true === (json_last_error() == JSON_ERROR_NONE)) {
				$this -> response -> setJson($json);
			}
		}

		$this -> response -> setInfo(curl_getinfo($curl));

		curl_close($curl);

		return $this;
	}
674172
public function sendHeaders()
    {
        foreach ($this->_headers as $key => $value) {
            if (is_array($value)) {
                foreach ($value as $v) {
                    header($key.': '.$v, false);
                }
            } else {
                header($key.': '.$value);
            }
        }

        return $this;
    }
1229011
public function send()
    {
        $request = $this->createRequest();

        $response = $this->httpClient->sendRequest($request);

        return $this->mapResponse((array) $this->parseResponse($response));
    }
1209579
public function send(): HttpResponse {
        $ch = $this->createCurl();
        $response = $this->execCurl($ch);
        curl_close($ch);

        return $response;
    }
662002
protected function sendHeader()
	{
		$this->openHandle();

		$target= $this->path.($this->query? '?'.$this->query : '' ).($this->fragment? '#'.$this->fragment : '' );

		$this->writeLine("{$this->method} {$target} HTTP/{$this->version}");
		$this->writeLine("Host: {$this->host}");

		foreach( $this->headers as $key=>$value ){
			$this->writeLine("$key: $value");
		}
		$this->writeLine('');
	}
480712
public function sendHeaders()
    {
        // Only check if we can send headers if we have headers to send
        if (count($this->_headersRaw) || count($this->_headers) || (200 != $this->_httpResponseCode)) {
            $this->canSendHeaders(true);
        } elseif (200 == $this->_httpResponseCode) {
            // Haven't changed the response code, and we have no headers
            return $this;
        }

        $httpCodeSent = false;

        foreach ($this->_headersRaw as $header) {
            if (!$httpCodeSent && $this->_httpResponseCode) {
                header($header, true, $this->_httpResponseCode);
                $httpCodeSent = true;
            } else {
                header($header);
            }
        }

        foreach ($this->_headers as $header) {
            if (!$httpCodeSent && $this->_httpResponseCode) {
                header($header['name'] . ': ' . $header['value'], $header['replace'], $this->_httpResponseCode);
                $httpCodeSent = true;
            } else {
                header($header['name'] . ': ' . $header['value'], $header['replace']);
            }
        }

        if (!$httpCodeSent) {
            header('HTTP/1.1 ' . $this->_httpResponseCode);
            $httpCodeSent = true;
        }

        return $this;
    }
635760
public function clear(): Response
	{
		$this->clearBody();

		$this->headers->clear();

		$this->cookies->clear();

		return $this;
	}
1303646
public function send() {
		
		$url = $this->url();

		// Set fields for post or put requests.
		$this->curl = curl_init();
		curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $this->method);
		if (in_array($this->method, ['POST', 'PUT'])) {
			$this->buildBody();
		} else {
			$this->header('Content-Type', null);
		}
		curl_setopt($this->curl, CURLOPT_URL, $url);
		curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);

		// Capture rate limit response headers.
		$rate_limit = [];
		curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$rate_limit) {
			$parts = explode(':', trim($header), 2);
			if (isset($parts[1]) && preg_match('/^X-RateLimit-(.*)/', $parts[0], $match)) {
				$rate_limit[$match[1]] = (int) $parts[1];
			}
			return strlen($header);
		});

		// Set authorization.
		$access_token = $this->client->accessToken();
		if ($access_token === null) {
			$this->setBearerToken($this->client->id());
		} else {
			$this->setBearerToken($access_token);
		}

		// Add headers.
		$headers = [];
		foreach ($this->headers as $name => $value) {
			if ($value !== null) {
				$headers[] = $name . ': ' . $value;
			}
			curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
		}

		// Allow the client to access the request before it is sent.
		$before = $this->client->before();
		if (is_callable($before)) {
			$before($this);
		}

		// Get response,
		$body = @curl_exec($this->curl);

		// Allow the client to access the request after it is sent.
		$after = $this->client->after();
		if (is_callable($after)) {
			$after($this);
		}

		// Get status and error info before closing the handle.
		$http_status = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
		$error_code = curl_errno($this->curl);
		$error_message = curl_error($this->curl);
		@curl_close($this->curl);

		// Check for curl error.
		if ($error_code > 0) {
			throw new NetworkException($error_message, $error_code);
		}

		return new Response($body, $http_status, $rate_limit);
	}
308446
public function sendHeaders()
    {
        if (!headers_sent()) {
            foreach ($this->headers as $header) {
                header($header, true);
            }
        }

        $this->headers = array();
        return $this;
    }
1089269
function response()
    {
        if (!$this->response) {
            $settings = new DataParseResponsePhp;
            $response = new HttpResponse(
                new BuildHttpResponse( BuildHttpResponse::parseWith($settings) )
            );

            $this->response = $response;
        }

        return $this->response;
    }
986499
public function sendHeaders()
    {
        // cookie
        foreach($this->cookies as $cookie)
        {
            $this->swooleResponse->cookie($cookie['key'], $cookie['value'], $cookie['expire'] ?? 0, $cookie['path'] ?? '/', $cookie['domain'] ?? '', $cookie['secure'] ?? false, $cookie['httponly'] ?? false);
        }
        // header
        foreach($this->getHeaders() as $name => $headers)
        {
            $this->swooleResponse->header($name, $this->getHeaderLine($name));
        }
        // status
        $this->swooleResponse->status($this->getStatusCode());
        return $this;
    }
1111036
protected function handleHead() : HttpResponse
    {
        $key = $this->request->key();

        if ( ! $fileMeta = $this->cache->get($key)) {
            return $this->response->send(null, HttpResponse::HTTP_NOT_FOUND);
        }

        $offset = $fileMeta['offset'] ?? false;

        if (false === $offset) {
            return $this->response->send(null, HttpResponse::HTTP_GONE);
        }

        return $this->response->send(null, HttpResponse::HTTP_OK, $this->getHeadersForHeadRequest($fileMeta));
    }
404475
public function sendHeaders()
    {
        // headers have already been sent by the developer
        if (headers_sent()) {
            return $this;
        }

        // headers
        foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) {
            $replace = 0 === strcasecmp($name, 'Content-Type');
            foreach ($values as $value) {
                header($name.': '.$value, $replace, $this->statusCode);
            }
        }

        // cookies
        foreach ($this->headers->getCookies() as $cookie) {
            header('Set-Cookie: '.$cookie->getName().strstr($cookie, '='), false, $this->statusCode);
        }

        // status
        header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);

        return $this;
    }
1018638
public function sendResponse()
  {
    # Set HTTP Response Code
    \http_response_code($this->getResponse()->getStatusCode());

    # Set All HTTP headers from Response Object
    foreach ($this->getResponse()->getHeaders() as $header => $value) {
      if (\is_array($value)) {
        $values = \implode(';',$value);
      } else {
        $values = $value;
      }

      \header($header.': '.$values);
    }

    # Remove the "x-powered-by" header set by PHP
    if (\function_exists('header_remove')) \header_remove('x-powered-by');

    # Set Cookies
    foreach ($this->cookies as $cookie)
    {
      \setCookie( $cookie['name'],
                  $cookie['value'],
                  $cookie['expire'] ?? 0,
                  $cookie['path'] ?? '',
                  $cookie['domain'] ?? '',
                  $cookie['secure'] ?? false,
                  $cookie['httponly'] ?? false
                );
    }

    ##
    ## Send a file or a body?
    ##
    if ( !empty($this->responseFile) ) {

      if (\file_exists($this->responseFile)) {
        # Debug log
        $this->getLogger()->debug('Sending file',[
          'code'=>$this->getResponse()->getStatusCode(),
          'headers'=>$this->getResponse()->getHeaders(),
          'file'=>$this->responseFile
        ]);

        # Send the file
        \readfile($this->responseFile);

      } else {
        # Log warning
        $this->getLogger()->warning('File not found',['file'=>$this->responseFile]);

        # Fake a response
        \response('',404);

        # Set HTTP Response Code
        \http_response_code(404);
      }

    } else {
      # Get body
      $body = (string)$this->response->getBody();

      # Debug log
      $this->getLogger()->debug('Sending body',[
        'code' => $this->getResponse()->getStatusCode(),
        'headers' => $this->getResponse()->getHeaders(),
        'size' => \strlen($body)
      ]);

      # Send the Body
      echo $body;
    }

    return $this;
  }