Generate headers for response
@param  array $files
@param  array $content_range
@return array
428955
protected function getNewHeaders(array $files, $content_range)
    {
        $headers = [
            'pragma' => 'no-cache',
            'cache-control' => 'no-store, no-cache, must-revalidate',
            'content-disposition' => 'inline; filename="files.json"',
            'x-content-type-options' => 'nosniff'
        ];

        if ($content_range && is_object($files[0]) && isset($files[0]->size) && $files[0]->size) {
            $headers['range'] = '0-' . ($this->fixIntegerOverflow($files[0]->size) - 1);
        }

        return $headers;
    }
671903
static function encodeBody ( $files )
    {
    	$headers  	= array();
		$body		= null;

		// 1. Add all the files to the post
		if (!empty($files))
		{
			foreach ($files as $name => $f)
			{
				$data     = false;
				$filename = false;

				if (isset($f['filename']))
				{
					$filename = $f['filename'];
				}

				if (!empty($f['file']))
				{
					$data = @file_get_contents($f['file']);
					if ($data === false)
					{
						throw new OAuthException2(sprintf('Could not read the file "%s" for request body', $f['file']));
					}
					if (empty($filename))
					{
						$filename = basename($f['file']);
					}
				}
				else if (isset($f['data']))
				{
					$data = $f['data'];
				}
				
				// When there is data, add it as a request body, otherwise silently skip the upload
				if ($data !== false)
				{
					if (isset($headers['Content-Disposition']))
					{
						throw new OAuthException2('Only a single file (or data) allowed in a signed PUT/POST request body.');
					}

					if (empty($filename))
					{
						$filename = 'untitled';
					}
					$mime  = !empty($f['mime']) ? $f['mime'] : 'application/octet-stream';
					
					$headers['Content-Disposition'] = 'attachment; filename="'.OAuthBodyContentDisposition::encodeParameterName($filename).'"';
					$headers['Content-Type']		= $mime;

					$body = $data;
				}
				
			}

			// When we have a body, add the content-length
			if (!is_null($body))
			{
				$headers['Content-Length'] = strlen($body);
			}
		}
		return array($headers, $body);
	}
316714
protected function getFilePayload(?array $files) : ?array
    {
        if (empty($files)) {
            return null;
        }

        $files = array_filter($files, function($file) {
            return $file instanceof ResourceSettings || (isset($file['key']) && isset($file['filename']));
        });

        return $files;
    }
444327
private function output_array($headers, $array) {
		header('Content-Type: text/csv; charset=utf-8');
		header('Content-Disposition: attachment; filename=' . $this->pager->get_classname() . '.csv');

		foreach ($headers as $header) {
			echo $header . ';';
		}
		echo "\n";
		foreach ($array as $values) {
			foreach ($values as $value) {
				echo $value . ';';
			}
			echo "\n";
		}
		exit;

		$result = $this->pager->page();
		foreach ($fields as $field) {
			echo $field . ';';
		}
		echo "\n";
		foreach ($this->pager->items as $item) {
			foreach ($fields as $field) {
				echo \Skeleton\Pager\Util::object_get_attribute($item, $field) . ';';
			}
			echo "\n";
		}
		exit;
	}
808119
private function getHeaders(array $headers)
    {
        $str = '';
        foreach ($headers as $key => $value) {
            $str .= "{$key}: {$value}\r\n";
        }

        return "--{$this->boundary}\r\n" . trim($str) . "\r\n\r\n";
    }
893054
private function createRange($ranges)
    {
        $rangeOfString = '';
        foreach ($ranges as $range) {
           $rangeOfString .= implode('', range($range[0], $range[2]));
        }

        return $rangeOfString;
    }
62459
private function setReponseHeaders($contentType = 'text/html', array $cookies = array())
    {
        $powered = Config::getParam('poweredBy', 'PSFS');
        header('X-Powered-By: ' . $powered);
        ResponseHelper::setStatusHeader($this->getStatusCode());
        ResponseHelper::setAuthHeaders($this->isPublicZone());
        ResponseHelper::setCookieHeaders($cookies);
        header('Content-type: ' . $contentType);

    }
175856
public static function formatHeadersForCurl(array $headers)
    {
        $curlHeaders = array();

        foreach ($headers as $key => $value) {
            $curlHeaders[] = $key . ': ' . $value;
        }

        return $curlHeaders;
    }
146850
public function getHeadersArray($EOL = Zend_Mime::LINEEND)
    {
        $headers = array();

        $contentType = $this->type;
        if ($this->charset) {
            $contentType .= '; charset=' . $this->charset;
        }

        if ($this->boundary) {
            $contentType .= ';' . $EOL
                          . " boundary=\"" . $this->boundary . '"';
        }

        $headers[] = array('Content-Type', $contentType);

        if ($this->encoding) {
            $headers[] = array('Content-Transfer-Encoding', $this->encoding);
        }

        if ($this->id) {
            $headers[]  = array('Content-ID', '<' . $this->id . '>');
        }

        if ($this->disposition) {
            $disposition = $this->disposition;
            if ($this->filename) {
                $disposition .= '; filename="' . $this->filename . '"';
            }
            $headers[] = array('Content-Disposition', $disposition);
        }

        if ($this->description) {
            $headers[] = array('Content-Description', $this->description);
        }

        if ($this->location) {
            $headers[] = array('Content-Location', $this->location);
        }

        if ($this->language){
            $headers[] = array('Content-Language', $this->language);
        }

        return $headers;
    }
34892
private static function range(ResponseInterface $response, string $range): ResponseInterface
    {
        $response = $response->withHeader('Accept-Ranges', 'bytes');

        if (empty($range) || !($range = self::parseRangeHeader($range))) {
            return $response;
        }

        list($first, $last) = $range;
        $size = $response->getBody()->getSize();

        if ($last === null) {
            $last = $size - 1;
        }

        return $response
            ->withStatus(206)
            ->withHeader('Content-Length', (string) ($last - $first + 1))
            ->withHeader('Content-Range', sprintf('bytes %d-%d/%d', $first, $last, $size));
    }
1277073
private function prepareFields(ApiContentType $contentType, $fields = null)
    {
        if ($fields !== null) {
            if (strpos($fields, ',') !== false) {
                return explode(',', $fields);
            }

            return array($fields);
        }

        $fields = array();
        $contentFields = $contentType->getFieldDefinitions();

        foreach ($contentFields as $field) {
            $fields[] = $field->identifier;
        }

        return $fields;
    }
1080539
private function formatOutputLocationArray($locations)
    {
        $formattedResponse = [];

        /**
         * @var LocationInterface $location
         */
        foreach ($locations as $location) {
            $formattedResponse[] = $this->formatOutputLocation($location);
        }

        return $formattedResponse;
    }
813938
public function getOutput( array &$headers = [] )
	{
		$this->prepareOptions();
		$this->prepareSearch();
		$this->prepareTree();

		switch ( $this->options->get( Opt::OUTPUT_TYPE ) )
		{
			case Opt::OUTPUT_TYPE_RAW :
				$headers['Content-Type'] = 'text/plain; charset=UTF-8';
				$currentFile             = $this->search->getCurrentFile();
				$output                  = 'Your current selection is not valid.';

				if ( $this->search->isCurrentFileValid() && is_file( $currentFile ) )
				{
					$fileEncoder = new FileEncoder( $currentFile );
					$output      = $fileEncoder->getFileContents();
				}

				break;

			case Opt::OUTPUT_TYPE_DOM:

				$this->tree->buildTree();
				$this->preparePage();

				$headers['Content-Type'] = 'text/html; charset=UTF-8';
				$output                  = $this->page->getDOMDocument();

				break;

			default:
				$output = 'No valid output type set.';
		}

		return $output;
	}
946851
public static function generateFile($file, array $content) {
		$string = static::buildIniString($content);

		return (bool)file_put_contents($file, $string);
	}
1041069
public function createUploadedFilesFromArray(array $files)
    {
        $uploadedFiles = [];

        if (isset($files['tmp_name']) && ! is_array($files['tmp_name'])) {
            $uploadedFiles[] = $this->createUploadedFile(
                $files['tmp_name'],
                $files['size'],
                $files['error'],
                $files['name'],
                $files['type']
            );
        } elseif (isset($files['tmp_name']) && is_array($files['tmp_name'])) {
            foreach ($files['tmp_name'] as $key => $file) {
                $uploadedFiles[] = $this->createUploadedFile(
                    $file,
                    $files['size'][$key],
                    $files['error'][$key],
                    $files['name'][$key],
                    $files['type'][$key]
                );
            }
        } else {
            foreach ($files as $key => $value) {
                $uploadedFiles[$key] = $this->createUploadedFilesFromArray($value);
            }
        }

        return $uploadedFiles;
    }
1323804
protected function getHttpRange($fileSize)
    {
        $rangeHeader = $this->app->getRequest()->getHeaderLine('Range');

        if (empty($rangeHeader) || $rangeHeader === '-') {
            return [0, $fileSize - 1];
        }
        if (!preg_match('/^bytes=(\d*)-(\d*)$/', $rangeHeader, $matches)) {
            return false;
        }
        if ($matches[1] === '') {
            $start = $fileSize - $matches[2];
            $end = $fileSize - 1;
        } elseif ($matches[2] !== '') {
            $start = $matches[1];
            $end = $matches[2];
            if ($end >= $fileSize) {
                $end = $fileSize - 1;
            }
        } else {
            $start = $matches[1];
            $end = $fileSize - 1;
        }
        if ($start < 0 || $start > $end) {
            return false;
        }

        return [$start, $end];
    }
590948
protected function prepareHeaders(array $headers)
    {
        $preparedHeaders = [];

        foreach ($headers as $strName => $varValue) {
            $preparedHeaders[] = $strName.': '.$varValue;
        }

        return $preparedHeaders;
    }