Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)
  • Sorry
    Small bug in the pastebin proxy.php file that stopped binary data (images etc.) working properly
    New version here
    https://pastebin.com/LgrsBY6t
    mh

    Ok guys and gals (and the devs)

    Here’s a modified proxy.php file for 0.1alpha15
    https://pastebin.com/MVBjNMLj

    This version checks what wrapper the requests are being sent with and performs any necessary code changes (keeping the overhead down for those without the curl wrapper).
    If a change of wrapper is detected its stored, the user is notified of the change and prompted to refresh their browser.
    mh ??

    Hi
    On testing some more of the servers under my control i’ve managed to see both types of results. i.e. those that need a read of at least 1 byte of data and those that don’t (to display header info)

    There are many differences between the environments on these servers but the one that seems to introduce this issue is when PHP is compiled with --with-curlwrappers

    Consider the code
    phpinfo(INFO_GENERAL);

    Search the resulting webpage for “curl” if you find --with-curlwrappers listed in the Configure Command section of phpinfo then you’ll also see the problem that this thread is about.

    Consider the following code

    $streamOptions = array('http'=>array('method'=>"GET",'host'=>'google.com'));
    $context = stream_context_create($streamOptions);
    $handle = fopen('https://google.com', "rb", false, $context);
    $meta = stream_get_meta_data($handle);
    echo '<pre><strong>stream_get_meta_data</strong><br>';
    print_r($meta);
    die;

    On a server WITHOUT php compiled with --with-curlwrappers i.e. what the developers of the plugin expect

    stream_get_meta_data
    Array
    (
        [wrapper_data] => Array
            (
                [0] => HTTP/1.0 301 Moved Permanently
                ... (data redacted here)
                [32] => X-Frame-Options: SAMEORIGIN
            )
    
        [wrapper_type] => http
        [stream_type] => tcp_socket/ssl
        [mode] => r+
        [unread_bytes] => 684
        [seekable] =>
        [uri] => https://google.com
        [timed_out] =>
        [blocked] => 1
        [eof] =>
    )

    On a server WITH php compiled with --with-curlwrappers

    stream_get_meta_data
    Array
    (
        [wrapper_data] => Array
            (
                [headers] => Array
                    (
                    )
    
                [readbuf] => Resource id #3
            )
    
        [wrapper_type] => cURL
        [stream_type] => cURL
        [mode] => rb
        [unread_bytes] => 0
        [seekable] =>
        [uri] => https://google.com
        [timed_out] =>
        [blocked] => 1
        [eof] =>
    )

    Note the differences in wrapper_type and stream_type
    The wrapper_type is the important one as to the format of the returned wrapper_data

    Ok Devs
    I’ve given you a fix (admittedly not the prettiest code) and now i’ve given you the info on why it happens.
    If i tidy my code and optimise it for both configurations do you think we can get it added to the source?
    mh

    And here’s a link to pastebin for the modified proxy.php file for 0.1alpha15 https://pastebin.com/Pq34R3J6
    mh

    Thread Starter mhume

    (@mhume)

    resolved in 0.1alpha15
    mh

    emile_allxs
    You’re welcome!) Sharing is caring

    For this problem consider the php

    error_reporting(E_ALL);
    $streamOptions = array('http'=>array('method'=>"GET",'host'=>'google.com'));
    $context = stream_context_create($streamOptions);
    $handle = fopen('https://google.com', "rb", false, $context);
    $meta = stream_get_meta_data($handle);
    echo '<pre><strong>$meta BEFORE read of one byte</strong><br>';
    print_r($meta);
    $one_byte = fread($handle, 1); // mh_edit this is used to stop the "bug" reported here https://bugs.php.net/bug.php?id=46896 where the responce headers are missing
    $meta = stream_get_meta_data($handle);
    echo '<br><strong>$meta AFTER read of one byte</strong><br>';
    print_r($meta);
    die;

    The output i get follows (some header content redacted from the second display of $meta)

    $meta BEFORE read of one byte
    Array
    (
        [wrapper_data] => Array
            (
                [headers] => Array
                    (
                    )
    
                [readbuf] => Resource id #3
            )
    
        [wrapper_type] => cURL
        [stream_type] => cURL
        [mode] => rb
        [unread_bytes] => 0
        [seekable] =>
        [uri] => https://google.com
        [timed_out] =>
        [blocked] => 1
        [eof] =>
    )
    
    $meta AFTER read of one byte
    Array
    (
        [wrapper_data] => Array
            (
                [headers] => Array
                    (
                        [0] => HTTP/1.1 301 Moved Permanently
                        [1] => Location: https://www.google.com/
                        [2] => Content-Type: text/html; charset=UTF-8
                        [3] => Date: Thu, 10 May 2012 14:53:37 GMT
                        [4] => Expires: Sat, 09 Jun 2012 14:53:37 GMT
                        [5] => Cache-Control: public, max-age=2592000
                        [6] => Server: gws
                        [7] => Content-Length: 219
                        [8] => X-XSS-Protection: 1; mode=block
                        [9] => X-Frame-Options: SAMEORIGIN
                        [10] => HTTP/1.1 302 Found
                        [11] => Location: https://www.google.co.uk/
                        [12] => Cache-Control: private
                        [13] => Content-Type: text/html; charset=UTF-8
                        ... (data redacted here)
                        [33] => Transfer-Encoding: chunked
                    )
    
                [readbuf] => Resource id #3
            )
    
        [wrapper_type] => cURL
        [stream_type] => cURL
        [mode] => rb
        [unread_bytes] => 4095
        [seekable] =>
        [uri] => https://google.com
        [timed_out] =>
        [blocked] => 1
        [eof] =>
    )

    As you can see the header data is in an array [headers] further down than your code expects and without the 1 bite read there is no header data at all. I can only assume its something to do with the version of php or something to do with the operating system.

    emile_all4xs, could you post your results from running the above code?

    Could another user who sees this problem implement my fix and leave a response here to let us know if it works for others?

    Hope this helps
    mh

    freeouir
    Please check out my latest post on the following thread https://www.ads-software.com/support/topic/plugin-repress-proxied-urls-seem-to-be-not-working?replies=8#post-2805384

    I’ve updated the code to work with 0.1alpha14
    mh

    Hi guys
    My previous post was for an earlier version of the plugin.
    I’ve moved my edits for proxy.php to the latest version of the plugin (0.1alpha14) and stuck it up on paste bin.
    It can be found here https://pastebin.com/hHP8TGj1

    emile_all4xs
    I’m just about to drop a mail to [email protected] referencing this thread with as many details as i can include. If you search the post on pastebin referenced above for mh_edit you’ll see where i have amended the code
    This all seems to come from a “bug” i seem to get on my server where the responce headers are missing until you read some data from the connection https://bugs.php.net/bug.php?id=46896

    Hope this helps!
    mh

    PS would post all requested data here but a little unsecure!)

    mhume

    (@mhume)

    I’ve run into the same problem (and fixed it)
    He’s my modified proxy.php file https://pastebin.com/p8Erciv9
    Hope this helps!)
    mh

Viewing 9 replies - 1 through 9 (of 9 total)