Send all headers

Sends any headers specified. If an {@link setHttpResponseCode() HTTP response code}
has been specified, it is sent with the first header.

@return \G4\Http\Response
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;
    }
1021465
public function send()
    {
        $this->hash();

        if ($data = $this->handle('beforeExecuteReturn')) {
            return $data;
        }

        if (!empty($this->payload)) {
            $this->serialized_payload = $this->handle('serialize', $this->payload);
        }

        $this->uri = $this->formatEndpoint();

        $this->handle('beforeExecute');

        $exception = false;
        $res       = null;

        try {
            $client = new Client();

            $res = $client->request(
                $this->method,
                $this->uri,
                $this->headers + $this->formatBody() + $this->options
            );

        } catch (Exception $e) {
            $exception = $e;
        }

        if (is_bool($exception) && $res instanceof Response) {
            $body = $this->handle('parse', $res->getBody());

            if ($data = $this->handle('afterExecuteReturn', $body)) {
                return $data;
            }

            $this->handle('afterExecute', $body);

            return $body;
        }

        $msg = null;

        if ($exception instanceof Exception) {
            $msg = $exception->getMessage();

            if ($exception instanceof RequestException) {
                $msg = $exception->getRequest();

                if ($exception->hasResponse()) {
                    $msg = $exception->getResponse()->getBody()->getContents();
                }
            }
        }

        return $this->handle('error', $msg, ['exception' => $exception instanceof Exception ? $exception : null]);
    }
820703
public function sendHeaders()
    {
        if ($this->headersSent) {
            return;
        }

        if (!isset($this->headers["Content-Length"])) {
            $this->sendContentLengthHeaders();
        }

        $this->httpResponse->writeHead($this->status, $this->headers);
        $this->headersSent = true;
    }
1126079
public function send()
    {
        // Check if headers are sent already.
        if (headers_sent() === false) {

            // Determine reason phrase
            if ($this->reasonPhrase === null) {
                $this->reasonPhrase = self::$messages[$this->statusCode];
            }

            // Send status code.
            header(sprintf('%s %s', $this->protocolVersion, $this->reasonPhrase), true, $this->statusCode);

            // Send headers.
            foreach ($this->headers as $header => $value) {
                header(sprintf('%s: %s', $header, $value), true, $this->statusCode);
            }

            // Send cookies.
            foreach ($this->cookies as $cookie) {
                setcookie($cookie['name'], $cookie['value'], $cookie['expire'],
                    $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httponly']);
            }

            // Send body.
            echo $this->body;
        }

        return $this;
    }
558010
public function send()
    {
        if ($this->sent === false) {
            $this->sendHeaders();
            $this->sendCookies();

            $content = (string)$this->getBody();
            if (!empty($content)) {
                echo $content;
            } else {
                if (is_string($this->file)) {
                    if (!file_exists($this->file)) {
                        throw new Exception('The requested file was not found');
                    }
                    $handle = fopen($this->file, 'r');

                    if ($handle !== false) {
                        fpassthru($handle);
                        fclose($handle);
                    }
                }
            }

            $this->sent = true;

            return $this;
        }

        throw new Exception('Response was already sent');
    }
312114
public function send()
    {
        $response = $this;

        /**
         * Headers
         */
        // Write Headers to swoole response
        foreach ($response->getHeaders() as $key => $value) {
            $this->swooleResponse->header($key, implode(';', $value));
        }

        /**
         * Cookies
         */
        foreach ((array)$this->cookies as $domain => $paths) {
            foreach ($paths ?? [] as $path => $item) {
                foreach ($item ?? [] as $name => $cookie) {
                    if ($cookie instanceof Cookie) {
                        $this->swooleResponse->cookie($cookie->getName(), $cookie->getValue() ? : 1, $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
                    }
                }
            }
        }

        /**
         * Status code
         */
        $this->swooleResponse->status($response->getStatusCode());

        /**
         * Body
         */
        $this->swooleResponse->end($response->getBody()->getContents());
    }
1190167
public function send()
	{
		if( $this->method === 'POST' )
			$this->addHeaderPair( 'Content-Length', mb_strlen( $this->data ) );
		if( !$this->headers->getFieldsByName( 'connection' ) )
			$this->addHeaderPair( 'Connection', 'close' );

		$result	= "";
		$fp = fsockopen( $this->host, $this->port, $errno, $errstr, 2 );
		if( !$fp )
			throw new RuntimeException( $errstr.' ('.$errno.')' );

		$uri	= $this->uri/*.( $this->port ? ':'.$this->port : "" )*/;
		$lines	= array(
			$this->method." ".$uri." HTTP/".$this->version,
			$this->headers->render(),
		);
		if( $this->method === 'POST' )
			$lines[]	= $this->data;
		$lines	= join( "\r\n", $lines );
		fwrite( $fp, $lines );																		//  send Request
		while( !feof( $fp ) )																		//  receive Response
			$result .= fgets( $fp, 1024 );															//  collect Response chunks
		fclose( $fp );																				//  close Connection
		$response	= Net_HTTP_Response_Parser::fromString( $result );
		if( count( $response->getHeader( 'Location' ) ) ){
			$location	= array_shift( $response->getHeader( 'Location' ) );
			$this->host	= parse_url( $location->getValue(), PHP_URL_HOST );
			$this->setPort( parse_url( $location->getValue(), PHP_URL_PORT ) );
			$this->setUri( parse_url( $location->getValue(), PHP_URL_PATH ) );
			return $this->send();
		}
		return $response;
	}
314632
public function sendHeaders()
    {
        foreach ($this->getHeaders() as $name => $values) {
            foreach ($values as $value) {
                header(sprintf('%s: %s', $name, $value), false);
            }
        }

        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);
	}
46986
public function send()
    {
        $this->client->notifyPlugins('beforeRequest', [$this]);
        if (isset($this->options['async'])) {
            $async = $this->options['async'];
            if (is_bool($async)) {
                $async = var_export($async, true);
            }
            $this->headers['x-arango-async'] = $async;
        }

        if (isset($this->options['isBatchPart']) && $this->options['isBatchPart'] === true) {
            //            $this->isBatchPart = true;
            $this->address = $this->client->endpoint . $this->path;

            //todo: Revisit this:
            return true;
        } else {
            if (null !== $this->options && (!array_key_exists(
                        'isBatchRequest',
                        $this->options
                    ) || (isset($this->options['isBatchRequest']) && $this->options['isBatchRequest'] !== true))
            ) {
                $this->headers['Content-Type'] = 'application/json';
            }
            $this->address  = $this->client->endpoint . $this->path;
            $this->response = $this->client->connector->send($this);
        }

        return $this->client->doRequest($this);
    }
78275
public function send()
     {
         $response = $this->getResponse();

         if (in_array($response->getStatusCode(), array(204, 304))) {
             $response->setContent(null);
         }

        //Send headers and content
        $this->sendHeaders()->sendContent();
        fastcgi_finish_request();
     }
106815
protected function sendHeaders()
    {
        $illuminateResponse = $this->getIlluminateResponse();

        /* RFC2616 - 14.18 says all Responses need to have a Date */
        if (! $illuminateResponse->headers->has('Date')) {
            $illuminateResponse->setDate(\DateTime::createFromFormat('U', time()));
        }

        // headers
        // allPreserveCaseWithoutCookies() doesn't exist before Laravel 5.3
        $headers = $illuminateResponse->headers->allPreserveCase();
        if (isset($headers['Set-Cookie'])) {
            unset($headers['Set-Cookie']);
        }
        foreach ($headers as $name => $values) {
            foreach ($values as $value) {
                $this->swooleResponse->header($name, $value);
            }
        }

        // status
        $this->swooleResponse->status($illuminateResponse->getStatusCode());

        // cookies
        // $cookie->isRaw() is supported after symfony/http-foundation 3.1
        // and Laravel 5.3, so we can add it back now
        foreach ($illuminateResponse->headers->getCookies() as $cookie) {
            $method = $cookie->isRaw() ? 'rawcookie' : 'cookie';
            $this->swooleResponse->$method(
                $cookie->getName(),
                $cookie->getValue(),
                $cookie->getExpiresTime(),
                $cookie->getPath(),
                $cookie->getDomain(),
                $cookie->isSecure(),
                $cookie->isHttpOnly()
            );
        }
    }
852813
public function send()
    {
        $this->sendHeaders()->sendContent();

        // close the request
        if (function_exists('fastcgi_finish_request')) {
            fastcgi_finish_request();
        } elseif (strtolower(PHP_SAPI) != 'cli') {
            if (ob_get_length()) {
                ob_end_flush();
            }
        }

        return $this;
    }
542542
private function sendHeaders()
    {
        $this->useCookies();
        $this->setProtocolAndCode();
        header(
            sprintf(
                "Content-Type: %s; charset=%s",
                $this->getContentType(),
                $this->getCharset()
            )
        );

        if (count($this->getHeaders())) {
            foreach ($this->getHeaders() as $header) {

                header($header);
            }
        }
    }
750692
public function toResponse()
    {
        $response = Http::getInstance()->response();
        $response->reset();
        $response->status($this->code);
        if (is_string($this->details)) {
            $response->body($this->details);
        } elseif (is_string($this->message)) {
            $response->body($this->message);
        }

        return $response;
    }
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;
    }
12709
public function send()
    {
        $allowed_status_codes = array_merge(array(200), $this->ignoredStatusCodes);
        $this->ignoredStatusCodes = array();

        try {
            $this->_setupCurl();
            $response = curl_exec($this->curl);

            if (!in_array(curl_getinfo($this->curl, CURLINFO_HTTP_CODE), $allowed_status_codes)) {
                if (curl_errno($this->curl)) {
                    throw new \RuntimeException('The HTTP request failed: ' . curl_error($this->curl));
                }
                throw new \RuntimeException('The HTTP request failed: unknown error.');
            }
            curl_close($this->curl);

            return $this->hasToDecodeResponse ? json_decode($response) : $response;
        } catch (Exception $e) {  }
    }