@param string  $http_verb
@param string  $method
@param string  $url
@param integer $timeout

@return array
438507
private function prepareStateForRequest($http_verb, $method, $url, $timeout)
    {
        $this->last_error = '';

        $this->request_successful = false;

        $this->last_response = array(
            'headers'     => null, // array of details from curl_getinfo()
            'httpHeaders' => null, // array of HTTP headers
            'body'        => null // content of the response
        );

        $this->last_request = array(
            'method'  => $http_verb,
            'path'    => $method,
            'url'     => $url,
            'body'    => '',
            'timeout' => $timeout,
        );

        return $this->last_response;
    }
690797
protected function verbToOperation($verb)
    {
        switch (strtoupper($verb)) {
            case Doozr_Http::REQUEST_METHOD_POST:
                $operation = 'create';
                break;

            case Doozr_Http::REQUEST_METHOD_GET:
                $operation = 'read';
                break;

            case Doozr_Http::REQUEST_METHOD_PUT:
                $operation = 'update';
                break;

            case Doozr_Http::REQUEST_METHOD_DELETE:
                $operation = 'delete';
                break;

            case Doozr_Http::REQUEST_METHOD_OPTIONS:
                $operation = 'options';
                break;

            case Doozr_Http::REQUEST_METHOD_HEAD:
                $operation = 'meta';
                break;

            default:
                $operation = 'read';
                break;
        }

        return $operation;
    }
276005
public function options()
    {
        if (!($this->response instanceof ResponseInterface)) {
            throw new MethodNotAllowed();
        }

        // Get all implemented methods for this resources
        $methods = get_class_methods(get_class($this));

        // Get supported verbs
        $validMethods = $this->container['validHttpVerbs'];

        // Loop though class functions/methods
        foreach ($methods as $key => &$method) {
            $method = strtoupper($method);
            // If class function/method isn't a verb, then unset it
            if (!in_array($method, $validMethods)) {
                unset($methods[$key]);
            }
        }

        // Set accept header
        $this->response = $this->response->withAddedHeader('Allow', implode(', ', $methods));

        // Prepare output
        $output = [];
        $output['Content-Type'] = $this->container['contentTypes'];
        $output['Accept'] = $this->container['acceptTypes'];

        foreach ($methods as $verb) {
            $doc = $this->parseMethodDoc($verb);

            // Check if there is any output to show
            if (!empty($doc)) {
                $output['methods'][$verb] = $doc;
            }
        }

        // return output
        return $output;
    }
1141498
public function route(
        string $method,
        string $pattern,
        callable $callback,
        int $priority = 0
    ): RouterInterface {
        //hard requirement
        if (!is_callable($callback)) {
            throw HttpException::forInvalidRouteCallback();
        }

        if (strtoupper($method) === 'ALL') {
            $method = '[a-zA-Z0-9]+';
        }

        //find and organize all the dynamic parameters
        preg_match_all('#(\:[a-zA-Z0-9\-_]+)|(\*\*)|(\*)#s', $pattern, $matches);

        $keys = array();
        if (isset($matches[0]) && is_array($matches[0])) {
            $keys = $matches[0];
        }

        //replace the :variable-_name01
        $regex = preg_replace('#(\:[a-zA-Z0-9\-_]+)#s', '*', $pattern);

        //replace the stars
        //* -> ([^/]+)
        $regex = str_replace('*', '([^/]+)', $regex);
        //** -> ([^/]+)([^/]+) -> (.*)
        $regex = str_replace('([^/]+)([^/]+)', '(.*)', $regex);

        //now form the event pattern
        $event = '#^' . $method . '\s' . $regex . '/*$#is';

        //we need the handler for later
        $handler = $this->getEventHandler();

        $handler->on(
            $event,
            function (
                RequestInterface $request,
                ...$args
            ) use (
                $handler,
                $callback,
                $pattern,
                $keys
            ) {
                $route = $handler->getMeta();
                $variables = array();
                $parameters = array();

                //sanitize the variables
                foreach ($route['variables'] as $i => $variable) {
                    //if it's a * variable
                    if (!isset($keys[$i]) || strpos($keys[$i], '*') === 0) {
                        //it's a variable
                        if (strpos($variable, '/') === false) {
                            $variables[] = $variable;
                            continue;
                        }

                        $variables = array_merge($variables, explode('/', $variable));
                        continue;
                    }

                    //if it's a :parameter
                    if (isset($keys[$i])) {
                        $key = substr($keys[$i], 1);
                        $parameters[$key] = $variable;
                    }
                }

                $request
                    ->setStage($parameters)
                    ->setRoute(array(
                        'event' => $route['event'],
                        'variables' => $variables,
                        'parameters' => $parameters
                    ));

                return call_user_func($callback, $request, ...$args);
            },
            $priority
        );

        return $this;
    }
1145880
public static function UrlExsist ($url, $timeout = 30, $protocol_version = self::VERSION_1_1) {
		$result = static::HeadRequest($url, $timeout, $protocol_version);
		return isset($result['http']['status']['code']) && $result['http']['status']['code'] !== '404';
	}
901466
protected function _sendRawRequest($url, $method = Request::METHOD_GET, $body = '', \Closure $initializeRequest = null)
    {
        $logSeverity = SolrLogManager::INFO;
        $exception = null;

        try {
            $request = $this->buildSolariumRequestFromUrl($url, $method);

            if($initializeRequest !== null) {
                $request = $initializeRequest($request);
            }

            $response = $this->executeRequest($request);
        } catch (HttpException $exception) {
            $logSeverity = SolrLogManager::ERROR;
            $response = new ResponseAdapter($exception->getBody(), $exception->getCode(), $exception->getMessage());
        }

        if ($this->configuration->getLoggingQueryRawPost() || $response->getHttpStatus() != 200) {
            $message = 'Querying Solr using '.$method;
            $this->writeLog($logSeverity, $message, $url, $response, $exception, $body);
        }

        return $response;
    }
216673
public function normalizeUrl($urls, $verb = 'GET'): array
    {
        $removeSlash = function ($url) use ($verb) {
            return $verb.ltrim($url, '/');
        };

        return array_map($removeSlash, $urls);
    }
761199
public function curl($url, $params_data = array(), $verb = "", $custom_method = "") {
		if ($this->version == 1) {
			// find the method from the URL.
			$method = preg_match("/api_action=[^&]*/i", $url, $matches);
			if ($matches) {
				$method = preg_match("/[^=]*$/i", $matches[0], $matches2);
				$method = $matches2[0];
			} elseif ($custom_method) {
				$method = $custom_method;
			}
		} elseif ($this->version == 2) {
			$method = $custom_method;
			$url .= "?api_key=" . $this->api_key;
		}

		$debug_str1 = "";

		$request = curl_init();

		$debug_str1 .= "\$ch = curl_init();\n";

		curl_setopt($request, CURLOPT_HEADER, 0);
		curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($request, CURLOPT_TIMEOUT, $this->timeout);

		$debug_str1 .= "curl_setopt(\$ch, CURLOPT_HEADER, 0);\n";
		$debug_str1 .= "curl_setopt(\$ch, CURLOPT_RETURNTRANSFER, true);\n";
		$debug_str1 .= "curl_setopt(\$ch, CURLOPT_TIMEOUT, " . $this->timeout . ");\n";

		if ($params_data && $verb == "GET") {
			if ($this->version == 2) {
				$url .= "&" . $params_data;
				curl_setopt($request, CURLOPT_URL, $url);
			}
		}
		else {
			curl_setopt($request, CURLOPT_URL, $url);
			if ($params_data && !$verb) {
				// if no verb passed but there IS params data, it's likely POST.
				$verb = "POST";
			} elseif ($params_data && $verb) {
				// $verb is likely "POST" or "PUT".
			} else {
				$verb = "GET";
			}
		}

		$debug_str1 .= "curl_setopt(\$ch, CURLOPT_URL, \"" . $url . "\");\n";

		if ($this->debug) {
			$this->dbg($url, 1, "pre", "Description: Request URL");
		}

		if ($verb == "POST" || $verb == "PUT" || $verb == "DELETE") {
			if ($verb == "PUT") {
				curl_setopt($request, CURLOPT_CUSTOMREQUEST, "PUT");

				$debug_str1 .= "curl_setopt(\$ch, CURLOPT_CUSTOMREQUEST, \"PUT\");\n";
			} elseif ($verb == "DELETE") {
				curl_setopt($request, CURLOPT_CUSTOMREQUEST, "DELETE");

				$debug_str1 .= "curl_setopt(\$ch, CURLOPT_CUSTOMREQUEST, \"DELETE\");\n";
			} else {
				$verb = "POST";
				curl_setopt($request, CURLOPT_POST, 1);

				$debug_str1 .= "curl_setopt(\$ch, CURLOPT_POST, 1);\n";
			}
			$data = "";
			if (is_array($params_data)) {
				foreach($params_data as $key => $value) {
					if (is_array($value)) {

						if (is_int($key)) {
							// array two levels deep
							foreach ($value as $key_ => $value_) {
								if (is_array($value_)) {
									foreach ($value_ as $k => $v) {
										$k = urlencode($k);
										$data .= "{$key_}[{$key}][{$k}]=" . urlencode($v) . "&";
									}
								} else {
									$data .= "{$key_}[{$key}]=" . urlencode($value_) . "&";
								}
							}
						} elseif (preg_match('/^field\[.*,0\]/', $key)) {
							// if the $key is that of a field and the $value is that of an array
							if (is_array($value)) {
								// then join the values with double pipes
								$value = implode('||', $value);
							}
							$data .= "{$key}=" . urlencode($value) . "&";
						} else {
							// IE: [group] => array(2 => 2, 3 => 3)
							// normally we just want the key to be a string, IE: ["group[2]"] => 2
							// but we want to allow passing both formats
							foreach ($value as $k => $v) {
								if (!is_array($v)) {
									$k = urlencode($k);
									$data .= "{$key}[{$k}]=" . urlencode($v) . "&";
								}
							}
						}

					} else {
						$data .= "{$key}=" . urlencode($value) . "&";
					}
				}
			} else {
				// not an array - perhaps serialized or JSON string?
				// just pass it as data
				$data = "data={$params_data}";
			}

			$data = rtrim($data, "& ");

			curl_setopt($request, CURLOPT_HTTPHEADER, array("Expect:"));

			$debug_str1 .= "curl_setopt(\$ch, CURLOPT_HTTPHEADER, array(\"Expect:\"));\n";

			if ($this->debug) {
				curl_setopt($request, CURLINFO_HEADER_OUT, 1);

				$debug_str1 .= "curl_setopt(\$ch, CURLINFO_HEADER_OUT, 1);\n";

				$this->dbg($data, 1, "pre", "Description: POST data");
			}

			curl_setopt($request, CURLOPT_POSTFIELDS, $data);

			$debug_str1 .= "curl_setopt(\$ch, CURLOPT_POSTFIELDS, \"" . $data . "\");\n";
		}

		curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 0);

		$debug_str1 .= "curl_setopt(\$ch, CURLOPT_SSL_VERIFYPEER, false);\n";
		$debug_str1 .= "curl_setopt(\$ch, CURLOPT_SSL_VERIFYHOST, 0);\n";

		$response = curl_exec($request);

		$curl_error = curl_error($request);
		
		if (!$response && $curl_error) {
			return $curl_error;
		}

		$debug_str1 .= "curl_exec(\$ch);\n";

		if ($this->debug) {
			$this->dbg($response, 1, "pre", "Description: Raw response");
		}

		$http_code = curl_getinfo($request, CURLINFO_HTTP_CODE);
		if (!preg_match("/^[2-3][0-9]{2}/", $http_code)) {
			// If not 200 or 300 range HTTP code, return custom error.
			return "HTTP code $http_code returned";
		}

		$debug_str1 .= "\$http_code = curl_getinfo(\$ch, CURLINFO_HTTP_CODE);\n";

		if ($this->debug) {
			$this->dbg($http_code, 1, "pre", "Description: Response HTTP code");

			$request_headers = curl_getinfo($request, CURLINFO_HEADER_OUT);

			$debug_str1 .= "\$request_headers = curl_getinfo(\$ch, CURLINFO_HEADER_OUT);\n";

			$this->dbg($request_headers, 1, "pre", "Description: Request headers");
		}

		curl_close($request);

		$debug_str1 .= "curl_close(\$ch);\n";

		$object = json_decode($response);

		if ($this->debug) {
			$this->dbg($object, 1, "pre", "Description: Response object (json_decode)");
		}
		if ( !is_object($object) || (!isset($object->result_code) && !isset($object->succeeded) && !isset($object->success)) ) {
			// add methods that only return a string
			$string_responses = array("tags_list", "segment_list", "tracking_event_remove", "contact_list", "form_html", "tracking_site_status", "tracking_event_status", "tracking_whitelist", "tracking_log", "tracking_site_list", "tracking_event_list");
			if (in_array($method, $string_responses)) {
				return $response;
			}

			$this->throwRequestException($response);
		}

		if ($this->debug) {
			echo "<textarea style='height: 300px; width: 600px;'>" . $debug_str1 . "</textarea>";
		}

		$object->http_code = $http_code;

		if (isset($object->result_code)) {
			$object->success = $object->result_code;

			if (!(int)$object->result_code) {
				$object->error = $object->result_message;
			}
		} elseif (isset($object->succeeded)) {
			// some calls return "succeeded" only
			$object->success = $object->succeeded;

			if (!(int)$object->succeeded) {
				$object->error = $object->message;
			}
		}

		return $object;
	}
1149343
public function getGlobal($api_method, $args = [], $timeout = 10)
    {
        $url = $this->api_endpoint . '/' . $api_method;
        return $this->makeRequest('get', $api_method, $args, $timeout, $url);
    }
1095859
public static function PostRequest ($url, $post_data = [], $timeout = 30, $protocol_version = self::VERSION_1_1, $options = []) {
		$parsed_url = parse_url($url);

		$host = $parsed_url['host'];
		if (!isset($parsed_url['port'])) {
			$port = $parsed_url['scheme'] === 'https' ? 443 : 80;
		}
		$path = $parsed_url['path'];

		$request_headers = [
			sprintf('POST %s HTTP/%s', $path, $protocol_version),
			sprintf('Host: %s', $host),
			'User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)',
			'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
			'Accept-Language: ja,en-us;q=0.7,en;q=0.3',
			'Accept-Encoding: gzip, deflate',
			'Connection: keep-alive',
			'Content-Type: application/x-www-form-urlencoded',
		];

		$enable_send_data = !empty($post_data);
		if ($enable_send_data) {
			$raw_post_data = http_build_query($post_data);
			$raw_post_data_length = strlen($raw_post_data);
			$request_headers[] = sprintf('Content-Length: %d', $raw_post_data_length);
		}
		if (isset($options['basic']) && is_array($options['basic'])) {
			$request_headers[] = sprintf('Authorization: Basic %s', base64_encode(implode(':', $options['basic'])));
		}

		$request_header = implode("\r\n", $request_headers) . "\r\n\r\n";

		$request = $enable_send_data ? sprintf("%s%s", $request_header, $raw_post_data) : $request_header;
		$request .= "\r\n\r\n";

		$schema = $parsed_url['scheme'] === 'https' ? 'ssl://' : '';

$data = http_build_query($post_data);

$header = array(
	'Content-Type: application/x-www-form-urlencoded',
	'Content-Length: '.strlen($data),
	'Authorization: Basic '.base64_encode('a:a'),
);

$context = array(
	'http' => array(
		'method'	=> 'POST',
		'header'	=> implode("\r\n", $header),
		'content'	=> $data,
	),
);

echo file_get_contents($url, false, stream_context_create($context));

		/*
		$fp = fsockopen($schema . $host, $port, $errno, $errstr, $timeout);
		if (!$fp) {
			CoreException::ScrubbedThrow(Status::SystemError(sprintf('%s (%s)', $errstr, $errno)));
		}

		fwrite($fp, $request_header);

		$return_data = [];
		$start_mts = microtime(true);
		while (!feof($fp) && (microtime(true) - $start_mts) < $timeout) {
			$return_data[] = trim(fgets($fp, 4000));
		}
		fclose($fp);

		$response_header = [];
		$response_body = [];
		$in_header = true;
		foreach ($return_data as $row) {
			if ($in_header && trim($row) === "") {
				$in_header = false;
				continue;
			}
			if ($in_header) {
				if (preg_match("/^HTTP\/(\d+.\d+) (\d+) (.+)$/", $row, $matches) === 1) {
					$response_header['http'] = [
						'version'	=> $matches[1],
						'status'	=> [
							'code'		=> $matches[2],
							'message'	=> $matches[3],
						],
					];
					continue;
				}
				if (preg_match("/^([^:]+): (.+)/", $row, $matches) === 1) {
					$response_header[$matches[1]] = $matches[2];
					continue;
				}
			} else {
				$response_body[] = $row;
			}
		}
		return [
			'header'	=> $response_header,
			'body'		=> $response_body,
		];
		*/
	}
1353924
public static function http_post($url, $param, $timeOut = 5, $connectTimeOut = 5) {
		$oCurl = curl_init ();
		if (stripos ( $url, "http://" ) !== FALSE || stripos ( $url, "https://" ) !== FALSE) {
			curl_setopt ( $oCurl, CURLOPT_SSL_VERIFYPEER, FALSE );
			curl_setopt ( $oCurl, CURLOPT_SSL_VERIFYHOST, false );
		}
		if (is_string ( $param )) {
			$strPOST = $param;
		} else {
			$aPOST = array ();
			foreach ( $param as $key => $val ) {
				$aPOST [] = $key . "=" . urlencode ( $val );
			}
			$strPOST = join ( "&", $aPOST );
		}
		curl_setopt($oCurl, CURLOPT_URL, $url );
		curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
		curl_setopt($oCurl, CURLOPT_POST, true );
		curl_setopt($oCurl, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($oCurl, CURLOPT_POSTFIELDS, $strPOST );
		curl_setopt($oCurl, CURLOPT_TIMEOUT, $timeOut);
        curl_setopt($oCurl, CURLOPT_CONNECTTIMEOUT, $connectTimeOut);
		$sContent = curl_exec ($oCurl );
		$aStatus = curl_getinfo ($oCurl );
        $error = curl_error($oCurl );
		curl_close ($oCurl );
		if (intval ($aStatus ["http_code"] ) == 200) {
			return array(
					'status' => true,
					'content' => $sContent,
					'code' => $aStatus ["http_code"],
			);
		} else {
			return array(
					'status' => false,
					'content' => json_encode(array("error" => $error, "url" => $url)),
					'code' => $aStatus ["http_code"],
			);
		}
	}
429335
public function goSingleGet($url = '', $query = [], $timeout = 30000, $headers = [])
    {
        if (empty($this->urlData)) {
            $this->urlData = self::parseUrl($url);
        } else {
            if (!empty($url)) {
                $this->urlData['path'] = $url;
            }
        }

        yield $this->goDnsLookup();
        $this->setHeaders($headers);

        //支持直接在url之后带参数形式的GET请求
        $q = '';
        if (!empty($this->urlData['query'])) {
            $q = ltrim($this->urlData['query'], '?');
        }

        if (!empty($query)) {
            $q .= (empty($q) ? '' : '&') . http_build_query($query) ;
        }

        return yield $this->getObject(Http::class, [$this, 'GET', $this->urlData['path'], $q, $timeout]);
    }
1265662
protected static function file_get_contents($url, $timeout)
    {
        $opts = array(
            'http' => array(
                'timeout' => $timeout,
            ),
        );
        return file_get_contents($url, false, stream_context_create($opts));
    }
489614
private function method($url, $closure, $method) {
			
		if(false === is_string($url)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($url)), E_USER_ERROR);
		}

		if(false === is_string($method)) {
			return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($method)), E_USER_ERROR);
		}

		$this -> method = $method;
		$this -> url 	= new URLParser($url);
		$this -> options[CURLOPT_CUSTOMREQUEST] = strtoupper($method);

		if(is_object($closure)) {
			call_user_func($closure, $this);
		}

		$this -> send();

		return $this;
	}
1072367
def rest_verbs(http_method_names=None):

    
    http_method_names = ['GET'] if (http_method_names is None) else http_method_names

    def decorator(func):

        WrappedRestView = type(
            six.PY3 and 'WrappedRestView' or b'WrappedRestView',
            (RestView,),
            {'__doc__': func.__doc__}
        )

        # Note, the above allows us to set the docstring.
        # It is the equivalent of:
        #
        #     class WrappedRestView(RestView):
        #         pass
        #     WrappedRestView.__doc__ = func.doc    <--- Not possible to do this

        # api_view applied without (method_names)
        assert not(isinstance(http_method_names, types.FunctionType)), \
            '@api_view missing list of allowed HTTP methods'

        # api_view applied with eg. string instead of list of strings
        assert isinstance(http_method_names, (list, tuple)), \
            '@api_view expected a list of strings, received %s' % type(http_method_names).__name__

        allowed_methods = set(http_method_names) | set(('options',))
        WrappedRestView.http_method_names = [method.lower() for method in allowed_methods]

        def handler(self, *args, **kwargs):
            return func(*args, **kwargs)

        for method in http_method_names:
            setattr(WrappedRestView, method.lower(), handler)

        WrappedRestView.__name__ = func.__name__

        WrappedRestView.renderer_classes = getattr(func, 'renderer_classes',
                                                  RestView.renderer_classes)

        WrappedRestView.parser_classes = getattr(func, 'parser_classes',
                                                RestView.parser_classes)

        WrappedRestView.authentication_classes = getattr(func, 'authentication_classes',
                                                        RestView.authentication_classes)

        WrappedRestView.throttle_classes = getattr(func, 'throttle_classes',
                                                  RestView.throttle_classes)

        WrappedRestView.permission_classes = getattr(func, 'permission_classes',
                                                    RestView.permission_classes)

        return WrappedRestView.as_view()
    return decorator
534125
function http($url, $method, $postfields=null, $headers=array())
    {
        $this->http_info = array();
        $ci = curl_init();
        /* Curl settings */
        curl_setopt($ci, CURLOPT_USERAGENT, self::USER_AGENT);
        curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, self::CONNECT_TIMEOUT);
        curl_setopt($ci, CURLOPT_TIMEOUT, self::REQUEST_TIMEOUT);
        curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);

        // Set request headers if any
        if (is_array($headers) && !empty($headers)){
            $this->http_request_headers = $headers;
            curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
        }

        curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, self::SSL_VERIFY_PEER);
        curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
        curl_setopt($ci, CURLOPT_HEADER, false);

        // Make sure the post fields are string
        if (is_array($postfields) && !empty($postfields)) {
            $postfields = http_build_query($postfields);
        }

        switch ($method) {
            case 'POST':
                curl_setopt($ci, CURLOPT_POST, true);
                if (!empty($postfields)) {
                    $this->http_post = $postfields;
                    curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
                }
                break;
            case 'DELETE':
                curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
                if (!empty($postfields)) {
                    $url = "{$url}?{$postfields}";
                }
        }

        curl_setopt($ci, CURLOPT_URL, $url);
        $response = curl_exec($ci);
        $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
        $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
        $this->http_url = $url;
        curl_close($ci);

        return $response;
    }
1097527
public static function HeadRequest ($url, $timeout = 30, $protocol_version = self::VERSION_1_1) {
		$parsed_url = parse_url($url);

		$host = $parsed_url['host'];
		if (!isset($parsed_url['port'])) {
			$port = $parsed_url['scheme'] === 'https' ? 443 : 80;
		}
		$path = $parsed_url['path'];

		$request_headers = [
			sprintf('HEAD %s HTTP/%s', $path, $protocol_version),
			'User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)',
			sprintf('Host: %s', $host),
			'Connection: Close',
		];
		$request_header = implode("\r\n", $request_headers) . "\r\n\r\n";

		$schema = $parsed_url['scheme'] === 'https' ? 'ssl://' : '';

		$fp = fsockopen($schema . $host, $port, $errno, $errstr, $timeout);
		if (!$fp) {
			CoreException::ScrubbedThrow(Status::SystemError(sprintf('%s (%s)', $errstr, $errno)));
		}

		fwrite($fp, $request_header);

		$return_data = [];
		while (!feof($fp)) {
			$return_data[] = trim(fgets($fp, 4000));
		}
		fclose($fp);

		$result = [];
		foreach ($return_data as $row) {
			if (preg_match("/^HTTP\/(\d+.\d+) (\d+) (.+)$/", $row, $matches) === 1) {
				$result['http'] = [
					'version'	=> $matches[1],
					'status'	=> [
						'code'		=> $matches[2],
						'message'	=> $matches[3],
					],
				];
				continue;
			}
			if (preg_match("/^([^:]+): (.+)/", $row, $matches) === 1) {
				$result[$matches[1]] = $matches[2];
				continue;
			}
		}
		return $result;
	}