wp_remote_retrieve_header example

$response_size = apply_filters( 'download_url_error_max_body_size', KB_IN_BYTES );

            $data['body'] = fread( $tmpf$response_size );
            fclose( $tmpf );
        }

        unlink( $tmpfname );

        return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) )$data );
    }

    $content_disposition = wp_remote_retrieve_header( $response, 'Content-Disposition' );

    if ( $content_disposition ) {
        $content_disposition = strtolower( $content_disposition );

        if ( str_starts_with( $content_disposition, 'attachment; filename=' ) ) {
            $tmpfname_disposition = sanitize_file_name( substr( $content_disposition, 21 ) );
        } else {
            $tmpfname_disposition = '';
        }

        // Potential file name must be valid string.

            if ( wp_remote_retrieve_response_code( $http_response ) !== 200 ) {
                return new WP_Error(
                    'http_' . wp_remote_retrieve_response_code( $http_response ),
                    wp_remote_retrieve_response_message( $http_response )
                );
            }

            $response_headers = array();

            foreach ( $caching_headers as $header => $callback ) {
                $header_values = wp_remote_retrieve_header( $http_response$header );
                if ( empty( $header_values ) ) {
                    continue;
                }
                $header_values = (array) $header_values;
                if ( empty( $callback ) || ( is_callable( $callback ) && count( array_filter( $header_values$callback ) ) > 0 ) ) {
                    $response_headers[ $header ] = $header_values;
                }
            }

            $page_caching_response_headers[] = $response_headers;
            $response_timing[]               = ( $end_time - $start_time ) * 1000;
        }
$test_url = get_permalink( $first_post->ID );
        }

        /* * Send a request to the site, and check whether * the 'X-Pingback' header is returned as expected. * * Uses wp_remote_get() instead of wp_remote_head() because web servers * can block head requests. */
        $response          = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
        $x_pingback_header = wp_remote_retrieve_header( $response, 'X-Pingback' );
        $pretty_permalinks = $x_pingback_header && get_bloginfo( 'pingback_url' ) === $x_pingback_header;

        if ( $pretty_permalinks ) {
            return true;
        }
    }

    /* * If it makes it this far, pretty permalinks failed. * Fallback to query-string permalinks. */
    
$url,
        array(
            'timeout'     => 2,
            'httpversion' => '1.0',
        )
    );

    if ( is_wp_error( $response ) ) {
        return false;
    }

    if ( wp_remote_retrieve_header( $response, 'X-Pingback' ) ) {
        return wp_remote_retrieve_header( $response, 'X-Pingback' );
    }

    // Not an (x)html, sgml, or xml page, no use going further.     if ( preg_match( '#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'Content-Type' ) ) ) {
        return false;
    }

    // Now do a GET since we're going to look in the HTML headers (and we're sure it's not a binary file).     $response = wp_safe_remote_get(
        $url,
        
Home | Imprint | This part of the site doesn't use cookies.