[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/includes/ -> functions-http.php (summary)

Functions that relate to HTTP requests On functions using the 3rd party library Requests: Their goal here is to provide convenient wrapper functions to the Requests library. There are 2 types of functions for each METHOD, where METHOD is 'get' or 'post' (implement more as needed) - yourls_http_METHOD() : Return a complete Response object (with ->body, ->headers, ->status_code, etc...) or a simple string (error message) - yourls_http_METHOD_body() : Return a string (response body) or null if there was an error

File Size: 727 lines (27 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 24 functions

  yourls_http_get()
  yourls_http_get_body()
  yourls_http_post()
  yourls_http_post_body()
  yourls_http_get_proxy()
  yourls_http_get_proxy_bypass_host()
  yourls_http_default_options()
  yourls_send_through_proxy()
  yourls_resolve_host()
  yourls_ip_is_local()
  yourls_host_is_local()
  yourls_restrict_remote_title_fetch()
  yourls_http_options_no_local_redirect()
  yourls_http_abort_local_redirect()
  yourls_http_request()
  yourls_http_user_agent()
  yourls_check_core_version()
  yourls_validate_core_version_response()
  yourls_get_version_from_zipball_url()
  yourls_is_valid_github_repo_url()
  yourls_validate_core_version_response_keys()
  yourls_maybe_check_core_version()
  yourls_skip_version_check()
  yourls_can_http_over_ssl()

Functions
Functions that are not part of a class:

yourls_http_get( $url, $headers = array()   X-Ref
Perform a GET request, return response object or error string message

Notable object properties: body, headers, status_code

return: mixed Response object, or error string
since: 1.7
param: string $url     URL to request
param: array $headers  HTTP headers to send
param: array $data     GET data
param: array $options  Options to pass to Requests

yourls_http_get_body( $url, $headers = array()   X-Ref
Perform a GET request, return body or null if there was an error

return: mixed String (page body) or null if error
since: 1.7
param: string $url     URL to request
param: array $headers  HTTP headers to send
param: array $data     GET data
param: array $options  Options to pass to Requests

yourls_http_post( $url, $headers = array()   X-Ref
Perform a POST request, return response object

Notable object properties: body, headers, status_code

return: mixed Response object, or error string
since: 1.7
param: string $url     URL to request
param: array $headers  HTTP headers to send
param: array $data     POST data
param: array $options  Options to pass to Requests

yourls_http_post_body( $url, $headers = array()   X-Ref
Perform a POST request, return body

Wrapper for yourls_http_request()

return: mixed String (page body) or null if error
since: 1.7
param: string $url     URL to request
param: array $headers  HTTP headers to send
param: array $data     POST data
param: array $options  Options to pass to Requests

yourls_http_get_proxy()   X-Ref
Get proxy information

return: mixed false if no proxy is defined, or string like '10.0.0.201:3128' or array like ('10.0.0.201:3128', 'username', 'password')
since: 1.7.1

yourls_http_get_proxy_bypass_host()   X-Ref
Get list of hosts that should bypass the proxy

return: mixed false if no host defined, or string like "example.com, *.mycorp.com"
since: 1.7.1

yourls_http_default_options()   X-Ref
Default HTTP requests options for YOURLS

For a list of all available options, see function request() in /includes/Requests/Requests.php

return: array Options
since: 1.7

yourls_send_through_proxy( $url )   X-Ref
Whether URL should be sent through the proxy server.

Concept stolen from WordPress. The idea is to allow some URLs, including localhost and the YOURLS install itself,
to be requested directly and bypassing any defined proxy.

return: bool true to request through proxy, false to request directly
since: 1.7
param: string $url URL to check

yourls_resolve_host(string $host)   X-Ref
Resolve a host name to a list of IP addresses

Returns every A and AAAA record found for $host, or an empty array if the host cannot be
resolved. Does not check the addresses in any way, see yourls_host_is_local() for this.

return: array       Array of IP addresses as strings, empty array if resolution failed
since: 1.10.5
param: string $host Host name to resolve (no brackets around IPv6 literals)

yourls_ip_is_local(string $ip)   X-Ref
Check if an IP address is not a public one (loopback, private, reserved or link-local)

Anything that is not a valid IP is considered non-public.

return: bool      true if the address is not public, or not an IP at all
since: 1.10.5
param: string $ip IP address, v4 or v6

yourls_host_is_local(string $host)   X-Ref
Check if a host points to a non-public address (loopback, private, reserved or link-local)

Accepts either a host name or an IP literal. A host name is resolved first, and considered
local as soon as one of its addresses is not public. A host that cannot be resolved is
considered local too.

Known limitation: this does not protect against DNS rebinding (attacker controlling a DNS server
with 0s TTL refresh, where evil-url.com could point to 1.2.3.4 (public) and then the next second point
to 10.0.0.1 (private). Let's consider this a low risk, and not worth the complexity of a DNS cache with TTL awareness.

return: bool        true if the host is not a public address or cannot be resolved
since: 1.10.5
param: string $host Host name or IP address. IPv6 literals can be bracketed or not.

yourls_restrict_remote_title_fetch()   X-Ref
Check if the destination of a remote title fetch must be restricted to public addresses

We want to avoid the situation where a public install of YOURLS is used to fetch titles from internal hosts,
and potentially leak information about them (SSRF and port scan / service discovery)
On a private install, the user is authenticated and (hopefully) trusted.

Public install can be: YOURLS_PRIVATE set to false, or having a public interface on top of a regular private
install. Checking constant YOURLS_USER covers both cases at once.

A one-liner plugin disables the filtering entirely (say, public install on a private network):
// Disable the restriction on remote title fetches (allow internal hosts)
yourls_add_filter( 'restrict_remote_title_fetch', 'yourls_return_false' );

return: bool  true if the fetch destination must be restricted to public addresses
since: 1.10.5

yourls_http_options_no_local_redirect()   X-Ref
HTTP request options that make a request fail when it is redirected to a non-public host

Redirects are still followed: dropping them would break 'http -> https', 'example.com ->
www.example.com', URL shorteners, or any legit 30x redirect. Instead, every hop
is checked before it is requested.

Meant to be merged into the $options of a single yourls_http_*() call, not to be added to
yourls_http_default_options() -- other requests (core version check, plugins) are not
triggered by an untrusted party.

return: array  Options to pass to yourls_http_get()
since: 1.10.5

yourls_http_abort_local_redirect(string $location)   X-Ref
Callback on the 'requests.before_redirect' hook: abort if the redirect target is not public

The exception thrown is a \WpOrg\Requests\Exception and not a plain \Exception, because this
is what yourls_http_request() catches -- anything else would escape and fatal.

return: void
since: 1.10.5
param: string $location URL the request is about to be redirected to

yourls_http_request( $type, $url, $headers, $data, $options )   X-Ref
Perform a HTTP request, return response object

return: object WpOrg\Requests\Response object
since: 1.7
param: string $type HTTP request type (GET, POST)
param: string $url URL to request
param: array $headers Extra headers to send with the request
param: array $data Data to send either as a query string for GET requests, or in the body for POST requests
param: array $options Options for the request (see /includes/Requests/Requests.php:request())

yourls_http_user_agent()   X-Ref
Return funky user agent string

return: string UA string
since: 1.5

yourls_check_core_version()   X-Ref
Check api.yourls.org if there's a newer version of YOURLS

This function collects various stats to help us improve YOURLS. See the blog post about it:
http://blog.yourls.org/2014/01/on-yourls-1-7-and-api-yourls-org/
Results of requests sent to api.yourls.org are stored in option 'core_version_checks' and is an object
with the following properties:
- failed_attempts : number of consecutive failed attempts
- last_attempt    : time() of last attempt
- last_result     : content retrieved from api.yourls.org during previous check
- version_checked : installed YOURLS version that was last checked

return: mixed JSON data if api.yourls.org successfully requested, false otherwise
since: 1.7

yourls_validate_core_version_response($json)   X-Ref
Make sure response from api.yourls.org is valid

1) we should get a json object with two following properties:
'latest' => a string representing a YOURLS version number, eg '1.2.3'
'zipurl' => a string for a zip package URL, from github, eg 'https://api.github.com/repos/YOURLS/YOURLS/zipball/1.2.3'
2) 'latest' and version extracted from 'zipurl' should match
3) the object should not contain any other key

return: bool   true if seems legit, false otherwise
since: 1.7.7
param: object $json  JSON object to check

yourls_get_version_from_zipball_url($zipurl)   X-Ref
Get version number from Github zipball URL (last part of URL, really)

return: string
since: 1.8.3
param: string $zipurl eg 'https://api.github.com/repos/YOURLS/YOURLS/zipball/1.2.3'

yourls_is_valid_github_repo_url($url)   X-Ref
Check if URL is from YOURLS/YOURLS repo on github

return: bool
since: 1.8.3
param: string $url  URL to check

yourls_validate_core_version_response_keys($json)   X-Ref
Check if object has only expected keys 'latest' and 'zipurl' containing strings

return: bool
since: 1.8.3
param: object $json

yourls_maybe_check_core_version()   X-Ref
Determine if we want to check for a newer YOURLS version (and check if applicable)

Currently checks are performed every 24h and only when someone is visiting an admin page.
In the future (1.8?) maybe check with cronjob emulation instead.

return: bool true if a check was needed and successfully performed, false otherwise
since: 1.7

yourls_skip_version_check()   X-Ref
Check if user setting for skipping version check is set

return: bool
since: 1.8.2

yourls_can_http_over_ssl()   X-Ref
Check if server can perform HTTPS requests, return bool

return: bool whether the server can perform HTTP requests over SSL
since: 1.7.1



Generated: Sat Aug 8 05:10:51 2026 Cross-referenced by PHPXref 0.7.1