Make WordPress Core

Ticket #11888: http-test.php

File http-test.php, 1.8 KB (added by Denis-de-Bernardy, 16 years ago)

test plugin

Line 
1<?php
2/*
3Plugin Name: HTTP Test plugin
4Plugin URI: http://www.semiologic.com/software/
5Description: Tests HTTP
6Version: 0.1
7Author: Denis de Bernardy
8Author URI: http://www.semiologic.com
9*/
10
11add_action('init', 'do_http_tests', 1000);
12
13function do_http_tests() {
14        if ( is_admin() || !isset($_GET['http_test']) )
15                return;
16       
17        header('Content-Type: text/plain; Charset: UTF-8');
18        $logfile = WP_CONTENT_DIR . '/http-tests.log';
19        ini_set('error_reporting', E_ALL);
20        ini_set('display_errors', '1');
21        switch ( $_GET['http_test'] ) {
22        case 'response':
23                $request = var_export(function_exists('apache_request_headers') ? apache_request_headers() : $_COOKIE, true);
24                $log = "Request:\n\n$request\n\n";
25
26                #$fp = fopen($logfile, 'a');
27                #fwrite($fp, $log);
28                #fclose($fp);
29                echo $log;
30                die;
31       
32        default:
33                $transport = _wp_http_get_object();
34                $transport = var_export($transport->_getTransport(), true);
35                $log = "Transport:\n\n$transport\n\n";
36
37                #$fp = fopen($logfile, 'a');
38                #fwrite($fp, $log);
39                #fclose($fp);
40                echo $log;
41
42                foreach ( array(
43                        get_option('home') . '/?http_test=response' => COOKIE_DOMAIN,
44                        'http://dev.semiologic.com/?http_test=response' => 'dev.semiologic.com',
45                        'https://dev.semiologic.com/?http_test=response' => 'dev.semiologic.com',
46                        ) as $url => $domain ) {
47                        $cookies = new WP_Http_Cookie(array( 'name' => 'test', 'value' => 'test', 'expires' => NULL, 'path' => '/', 'domain' => $domain, ));
48                        $args = array('cookies' => array($cookies), 'headers' => array( 'Custom' => 'Headers'));
49                       
50                        $request = var_export($args, true);
51                        $log = "Request to $url:\n\n$request\n\n";
52                       
53                        echo $log;
54                       
55                        $response = var_export(wp_remote_get($url, $args), true);
56                        $log = "Response from $url:\n\n$response\n\n";
57
58                        #$fp = fopen($logfile, 'a');
59                        #fwrite($fp, $log);
60                        #fclose($fp);
61                        echo $log;
62                }
63                die;
64        }
65}
66?>