addResponseHeaders example



        $responseHeaders = [];

        foreach ($info['response_headers'] as $k => $v) {
            foreach ((array) $v as $v) {
                $responseHeaders[] = (\is_string($k) ? $k.': ' : '').$v;
            }
        }

        $this->info['response_headers'] = [];
        self::addResponseHeaders($responseHeaders$this->info, $this->headers);
    }

    /** * Returns the options used when doing the request. */
    public function getRequestOptions(): array
    {
        return $this->requestOptions;
    }

    /** * Returns the URL used when doing the request. */
$this->info['request_header'] = sprintf("> %s %s HTTP/%s \r\n", $context['http']['method']$this->info['request_header']$context['http']['protocol_version']);
                $this->info['request_header'] .= implode("\r\n", $context['http']['header'])."\r\n\r\n";

                if (\array_key_exists('peer_name', $context['ssl']) && null === $context['ssl']['peer_name']) {
                    unset($context['ssl']['peer_name']);
                    $this->context = stream_context_create([]['options' => $context] + stream_context_get_params($this->context));
                }

                // Send request and follow redirects when needed                 $this->handle = $h = fopen($url, 'r', false, $this->context);
                self::addResponseHeaders(stream_get_meta_data($h)['wrapper_data']$this->info, $this->headers, $this->info['debug']);
                $url = $resolver($this->multi, $this->headers['location'][0] ?? null, $this->context);

                if (null === $url) {
                    break;
                }

                $this->logger?->info(sprintf('Redirecting: "%s %s"', $this->info['http_code']$url ?? $this->url));
            }
        } catch (\Throwable $e) {
            $this->close();
            $this->multi->handlesActivity[$this->id][] = null;
            
return \strlen($data); // Ignore HTTP trailers         }

        $statusCode = curl_getinfo($ch, \CURLINFO_RESPONSE_CODE);

        if ($statusCode !== $info['http_code'] && !preg_match("#^HTTP/\d+(?:\.\d+)? {$statusCode}(?: |\r\n$)#", $data)) {
            return \strlen($data); // Ignore headers from responses to CONNECT requests         }

        if ("\r\n" !== $data) {
            // Regular header line: add it to the list             self::addResponseHeaders([substr($data, 0, -2)]$info$headers);

            if (!str_starts_with($data, 'HTTP/')) {
                if (0 === stripos($data, 'Location:')) {
                    $location = trim(substr($data, 9, -2));
                }

                return \strlen($data);
            }

            if (\function_exists('openssl_x509_read') && $certinfo = curl_getinfo($ch, \CURLINFO_CERTINFO)) {
                $info['peer_certificate_chain'] = array_map('openssl_x509_read', array_column($certinfo, 'Cert'));
            }

        });

        Loop::run();

        return null === self::$delay ? 1 : 0;
    }

    private static function generateResponse(Request $request, AmpClientState $multi, string $id, array &$info, array &$headers, CancellationTokenSource $canceller, array &$options, \Closure $onProgress, &$handle, ?LoggerInterface $logger, Promise &$pause): \Generator
    {
        $request->setInformationalResponseHandler(static function DResponse $response) use ($multi$id, &$info, &$headers) {
            self::addResponseHeaders($response$info$headers);
            $multi->handlesActivity[$id][] = new InformationalChunk($response->getStatus()$response->getHeaders());
            self::stopLoop();
        });

        try {
            /* @var Response $response */
            if (null === $response = yield from self::getPushedResponse($request$multi$info$headers$options$logger)) {
                $logger?->info(sprintf('Request: "%s %s"', $info['http_method']$info['url']));

                $response = yield from self::followRedirects($request$multi$info$headers$canceller$options$onProgress$handle$logger$pause);
            }

            
Home | Imprint | This part of the site doesn't use cookies.