Implementation from Zend\Diactoros\marshalHeadersFromSapi().
6284
public static function getHeadersFromServer(array $server): array
    {
        $headers = [];
        foreach ($server as $key => $value) {
            // Apache prefixes environment variables with REDIRECT_
            // if they are added by rewrite rules
            if (0 === \strpos($key, 'REDIRECT_')) {
                $key = \substr($key, 9);

                // We will not overwrite existing variables with the
                // prefixed versions, though
                if (\array_key_exists($key, $server)) {
                    continue;
                }
            }

            if ($value && 0 === \strpos($key, 'HTTP_')) {
                $name = \strtr(\strtolower(\substr($key, 5)), '_', '-');
                $headers[$name] = $value;

                continue;
            }

            if ($value && 0 === \strpos($key, 'CONTENT_')) {
                $name = 'content-'.\strtolower(\substr($key, 8));
                $headers[$name] = $value;

                continue;
            }
        }

        return $headers;
    }
798840
protected function setHeaderCommon($headerFeatures = [])
    {
        $sReturn = [];
        $this->initializeSprGlbAndSession();
        $sHK     = $this->tCmnSuperGlobals->get('specialHook');
        if (!is_null($sHK) && (in_array('noHeader', $sHK))) {
            return ''; // no Header
        }
        $fixedHeaderElements = [
            'start'    => '<!DOCTYPE html>',
            'lang'     => $this->setHeaderLanguage($headerFeatures),
            'head'     => '<head>',
            'charset'  => '<meta charset="utf-8" />',
            'viewport' => '<meta name="viewport" content="width=device-width height=device-height initial-scale=1" />',
        ];
        if ($headerFeatures !== []) {
            $aFeatures = [];
            foreach ($headerFeatures as $key => $value) {
                $aFeatures[] = $this->setHeaderFeatures($key, $value);
            }
            return implode('', $fixedHeaderElements) . implode('', $aFeatures) . '</head>' . '<body>';
        }
        $sReturn[] = implode('', $fixedHeaderElements) . '</head>' . '<body>'
            . '<p style="background-color:red;color:#FFF;">The parameter sent to '
            . __FUNCTION__ . ' must be a non-empty array</p>' . $this->setFooterCommon();
        throw new \Exception(implode('', $sReturn));
    }
433316
public function initHeaders()
    {
        if (!isset($this->headers)) {
            $this->headers = new HeadersObject($this->determineHeaders());
        }
        
        return $this->headers;
    }
267352
public void encodeHeaders(int streamId, ByteBuf out, Http2Headers headers, SensitivityDetector sensitivityDetector)
            throws Http2Exception {
        if (ignoreMaxHeaderListSize) {
            encodeHeadersIgnoreMaxHeaderListSize(out, headers, sensitivityDetector);
        } else {
            encodeHeadersEnforceMaxHeaderListSize(streamId, out, headers, sensitivityDetector);
        }
    }
329735
private static function getHeadersFromInput ()
	{
		// getallheaders available, use that
		if (function_exists('getallheaders')) return getallheaders();

		// getallheaders not available: manually extract 'm
		$headers = [];
		foreach ($_SERVER as $name => $value)
		{
			if (substr($name, 0, 5) == 'HTTP_') {
			    $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
				$headers[$key] = $value;
			} else if (strtolower (substr ($name, 0, 7)) == 'content') {
                $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', $name))));
				$headers[$key] = $value;
			}
		}
		return $headers;
	}
499247
private function read_header()
    {
        $this->seek(0, IO::SEEK_SET);

        $magic = $this->read(DataIO::magic_size());

        if (strlen($magic) < DataIO::magic_size())
            throw new DataIoException(
                'Not an Avro data file: shorter than the Avro magic block');

        if (DataIO::magic() != $magic) {

            throw new DataIoException(
                sprintf('Not an Avro data file: %s does not match %s',
                    $magic, DataIO::magic()));
        }

        $this->metadata = $this->datum_reader->read_data(DataIO::metadata_schema(),
            DataIO::metadata_schema(),
            $this->decoder);
        $this->sync_marker = $this->read(DataIO::SYNC_SIZE);
    }
1373222
private WsByteBuffer[] marshallAddedHeaders(WsByteBuffer[] inBuffers, int index) {
        WsByteBuffer[] buffers = inBuffers;
        buffers[index] = allocateBuffer(this.outgoingHdrBufferSize);
        for (HeaderElement elem = this.hdrSequence; null != elem; elem = elem.nextSequence) {
            if (elem.wasAdded()) {
                buffers = marshallHeader(buffers, elem);
            }
        }
        // add second EOL
        buffers = putBytes(BNFHeaders.EOL, buffers);
        buffers = flushCache(buffers);
        // flip the last buffer now that we're done
        buffers[buffers.length - 1].flip();
        return buffers;
    }
770432
public function setHttpClient($client,
        $applicationId = 'MyCompany-MyApp-1.0', $clientId = null,
        $developerKey = null)
    {
        if ($client === null) {
            $client = new Zend_Http_Client();
        }
        if (!$client instanceof Zend_Http_Client) {
            require_once 'Zend/Gdata/App/HttpException.php';
            throw new Zend_Gdata_App_HttpException(
                'Argument is not an instance of Zend_Http_Client.');
        }

        if ($clientId != null) {
            $client->setHeaders('X-GData-Client', $clientId);
        }

        if ($developerKey != null) {
            $client->setHeaders('X-GData-Key', 'key='. $developerKey);
        }

        return parent::setHttpClient($client, $applicationId);
    }
1302683
public function headers() {
    $headers = array();
    $readers = array();
    $writers = array();

    // Create the rule strings. We need two copies, one for READ and
    // one for WRITE.
    foreach ($this->rules as $rule) {
      // We generate read and write rules separately so that the
      // generation logic has a chance to respond to the differences
      // allowances for READ and WRITE ACLs.
      if (self::READ & $rule['mask']) {
        $ruleStr = $this->ruleToString(self::READ, $rule);
        if (!empty($ruleStr)) {
          $readers[] = $ruleStr;
        }
      }
      if (self::WRITE & $rule['mask']) {
        $ruleStr = $this->ruleToString(self::WRITE, $rule);
        if (!empty($ruleStr)) {
          $writers[] = $ruleStr;
        }
      }
    }

    // Create the HTTP headers.
    if (!empty($readers)) {
      $headers[self::HEADER_READ] = implode(',', $readers);
    }
    if (!empty($writers)) {
      $headers[self::HEADER_WRITE] = implode(',', $writers);
    }

    return $headers;
  }
813616
private Map<String, String> getHttpHeaderBasic() throws Exception {
        
        return new HashMap<String, String>(){{
            put("Authorization", "Basic " + getHttpHeaderBasicKey());
        }};
    }
567009
protected function dispatchHeaders($headersAsString)
    {
        $headers = array();

        foreach ($headersAsString as $header) {
            $headerData = $this->dispatchHeaderValue($header);

            if (is_null($headerData)) {
                continue;
            }

            $headers[$headerData['name']] = $headerData['value'];
        }

        return $headers;
    }
982645
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
    {
        // Make sure we're properly connected
        if (! $this->socket) {

            throw new Zend_Http_Client_Adapter_Exception('Trying to write but we are not connected');
        }

        $host = $uri->getHost();
        $host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
        if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) {

            throw new Zend_Http_Client_Adapter_Exception('Trying to write but we are connected to the wrong host');
        }

        // Save request method for later
        $this->method = $method;

        // Build request headers
        $path = $uri->getPath();
        if ($uri->getQuery()) $path .= '?' . $uri->getQuery();
        $request = "{$method} {$path} HTTP/{$http_ver}\r\n";
        foreach ($headers as $k => $v) {
            if (is_string($k)) $v = ucfirst($k) . ": $v";
            $request .= "$v\r\n";
        }

        if(is_resource($body)) {
            $request .= "\r\n";
        } else {
            // Add the request body
            $request .= "\r\n" . $body;
        }

        // Send the request
        if (! @fwrite($this->socket, $request)) {

            throw new Zend_Http_Client_Adapter_Exception('Error writing request to server');
        }

        if(is_resource($body)) {
            if(stream_copy_to_stream($body, $this->socket) == 0) {

                throw new Zend_Http_Client_Adapter_Exception('Error writing request to server');
            }
        }

        return $request;
    }
1219796
public static function setHttpHeaders(){
		if(!is_array(self::$httpHeaders)){
			self::$httpHeaders=array();
			$httpHeaders=$_SERVER;
			foreach($httpHeaders as $key=>$value)
				if(substr($key,0,5)=='HTTP_')
                			self::$httpHeaders[$key]=$value;
			}
		}
958747
public function marshall()
    {
        $collection = $this->getToMarshall();
        $ctx = $this->getContext();
        $access = $ctx->getStreamAccess();

        $valueArray = $collection->getArrayCopy();
        $valueArrayVarName = $ctx->generateVariableName($valueArray);

        $arrayArgs = new PhpArgumentCollection();
        if (($count = count($collection)) > 0) {
            foreach ($ctx->popFromVariableStack($count) as $itemName) {
                $arrayArgs[] = new PhpArgument(new PhpVariable($itemName));
            }
        }

        try {
            $access->writeVariable($valueArrayVarName);
            $access->writeEquals($ctx->mustFormatOutput());
            $access->writeFunctionCall('array', $arrayArgs);
            $access->writeSemicolon($ctx->mustFormatOutput());

            $collectionVarName = $ctx->generateVariableName($collection);
            $access->writeVariable($collectionVarName);
            $access->writeEquals($ctx->mustFormatOutput());
            $collectionArgs = new PhpArgumentCollection(array(new PhpArgument(new PhpVariable($valueArrayVarName))));
            $access->writeInstantiation(get_class($collection), $collectionArgs);
            $access->writeSemicolon($ctx->mustFormatOutput());

            $ctx->pushOnVariableStack($collectionVarName);
        } catch (StreamAccessException $e) {
            $msg = "An error occured while marshalling a collection into PHP source code.";
            throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
        }
    }
1361296
public function writeMessage(Zend_Amf_Parse_OutputStream $stream)
    {
        $objectEncoding = $this->_objectEncoding;

        //Write encoding to start of stream. Preamble byte is written of two byte Unsigned Short
        $stream->writeByte(0x00);
        $stream->writeByte($objectEncoding);

        // Loop through the AMF Headers that need to be returned.
        $headerCount = count($this->_headers);
        $stream->writeInt($headerCount);
        foreach ($this->getAmfHeaders() as $header) {
            $serializer = new Zend_Amf_Parse_Amf0_Serializer($stream);
            $stream->writeUTF($header->name);
            $stream->writeByte($header->mustRead);
            $stream->writeLong(Zend_Amf_Constants::UNKNOWN_CONTENT_LENGTH);
            if (is_object($header->data)) {
                // Workaround for PHP5 with E_STRICT enabled complaining about
                // "Only variables should be passed by reference"
                $placeholder = null;
                $serializer->writeTypeMarker($placeholder, null, $header->data);
            } else {
                $serializer->writeTypeMarker($header->data);
            }
        }

        // loop through the AMF bodies that need to be returned.
        $bodyCount = count($this->_bodies);
        $stream->writeInt($bodyCount);
        foreach ($this->_bodies as $body) {
            $serializer = new Zend_Amf_Parse_Amf0_Serializer($stream);
            $stream->writeUTF($body->getTargetURI());
            $stream->writeUTF($body->getResponseURI());
            $stream->writeLong(Zend_Amf_Constants::UNKNOWN_CONTENT_LENGTH);
            $bodyData = $body->getData();
            $markerType = ($this->_objectEncoding == Zend_Amf_Constants::AMF0_OBJECT_ENCODING) ? null : Zend_Amf_Constants::AMF0_AMF3;
            if (is_object($bodyData)) {
                // Workaround for PHP5 with E_STRICT enabled complaining about
                // "Only variables should be passed by reference"
                $placeholder = null;
                $serializer->writeTypeMarker($placeholder, $markerType, $bodyData);
            } else {
                $serializer->writeTypeMarker($bodyData, $markerType);
            }
        }

        return $this;
    }
30275
private function parseHeaders() {

            foreach($this->amfResponse->getHeaders() as $header) {

                switch($header['name']) {

                    case 'ReplaceGatewayUrl' :
                        if (is_string($header['data'])) {
                            $this->endPoint = $header['data'];
                        }
                        break;

                }


            }

        }
1300853
def marshal_dump
      {
        method: method,
        body: body,
        headers: headers,
        path: path,
        params: params,
        options: options
      }
    end