- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Http;
|
|
|
|
/**
|
|
* Hilfsklasse für erweiterte Header-Funktionen ohne Modifikation der Headers-Klasse
|
|
*/
|
|
final readonly class HeaderManipulator
|
|
{
|
|
/**
|
|
* Konvertiert einen Header-String in ein Headers-Objekt
|
|
*/
|
|
public static function fromString(string $headersRaw): Headers
|
|
{
|
|
$headers = new Headers();
|
|
// Zeilenumbrüche vereinheitlichen und in Zeilen aufteilen
|
|
$lines = preg_split('/\r\n|\n|\r/', $headersRaw);
|
|
|
|
// Die erste Zeile kann die Status-Zeile sein, die überspringen wir
|
|
$statusLineFound = false;
|
|
|
|
foreach ($lines as $line) {
|
|
// Leere Zeilen überspringen
|
|
if (trim($line) === '') {
|
|
continue;
|
|
}
|
|
|
|
// Status-Zeile (HTTP/1.1 200 OK) überspringen
|
|
if (! $statusLineFound && preg_match('/^HTTP\/\d\.\d\s+\d+/', $line)) {
|
|
$statusLineFound = true;
|
|
|
|
continue;
|
|
}
|
|
|
|
// Header im Format "Name: Wert" parsen
|
|
if (preg_match('/^([^:]+):\s*(.*)$/', $line, $matches)) {
|
|
$name = $matches[1];
|
|
$value = $matches[2];
|
|
|
|
$headers = $headers->withAdded($name, $value);
|
|
}
|
|
}
|
|
|
|
return $headers;
|
|
}
|
|
|
|
/**
|
|
* Formatiert Headers für cURL
|
|
*/
|
|
public static function formatForCurl(Headers $headers): array
|
|
{
|
|
$formattedHeaders = [];
|
|
|
|
foreach ($headers->all() as $name => $values) {
|
|
foreach ($values as $value) {
|
|
$formattedHeaders[] = "$name: $value";
|
|
}
|
|
}
|
|
|
|
return $formattedHeaders;
|
|
}
|
|
}
|