Skip to content

Parser

HTTP Response Parser

  • Full name: \SimplePie\HTTP\Parser

Constants

Constant Visibility Type Value
STATE_HTTP_VERSION private 'http_version'
STATE_STATUS private 'status'
STATE_REASON private 'reason'
STATE_NEW_LINE private 'new_line'
STATE_BODY private 'body'
STATE_NAME private 'name'
STATE_VALUE private 'value'
STATE_VALUE_CHAR private 'value_char'
STATE_QUOTE private 'quote'
STATE_QUOTE_ESCAPED private 'quote_escaped'
STATE_QUOTE_CHAR private 'quote_char'
STATE_CHUNKED private 'chunked'
STATE_EMIT private 'emit'
STATE_ERROR private false

Properties

http_version

HTTP Version

public float $http_version

status_code

Status code

public int $status_code

reason

Reason phrase

public string $reason

headers

Key/value pairs of the headers

public array $headers

body

Body of the response

public string $body

state

Current state of the state machine

protected self::STATE_* $state

data

Input data

protected string $data

data_length

Input data length (to avoid calling strlen() everytime this is needed)

protected int $data_length

position

Current position of the pointer

protected int $position

name

Name of the hedaer currently being parsed

protected string $name

value

Value of the hedaer currently being parsed

protected string $value

Methods

__construct

Create an instance of the class with the input data

public __construct(string $data): mixed

Parameters:

Parameter Type Description
$data string Input data

parse

Parse the input data

public parse(): bool

Return Value:

true on success, false on failure


has_data

Check whether there is data beyond the pointer

protected has_data(): bool

Return Value:

true if there is further data, false if not


is_linear_whitespace

See if the next character is LWS

protected is_linear_whitespace(): bool

Return Value:

true if the next character is LWS, false if not


http_version

Parse the HTTP version

protected http_version(): mixed

status

Parse the status code

protected status(): mixed

reason

Parse the reason phrase

protected reason(): mixed

new_line

Deal with a new line, shifting data around as needed

protected new_line(): mixed

name

Parse a header name

protected name(): mixed

linear_whitespace

Parse LWS, replacing consecutive LWS characters with a single space

protected linear_whitespace(): mixed

value

See what state to move to while within non-quoted header values

protected value(): mixed

value_char

Parse a header value while outside quotes

protected value_char(): mixed

quote

See what state to move to while within quoted header values

protected quote(): mixed

quote_char

Parse a header value while within quotes

protected quote_char(): mixed

quote_escaped

Parse an escaped character within quotes

protected quote_escaped(): mixed

body

Parse the body

protected body(): mixed

chunked

Parsed a "Transfer-Encoding: chunked" body

protected chunked(): mixed

prepareHeaders

Prepare headers (take care of proxies headers)

public static prepareHeaders(string $headers, int $count = 1): string
  • This method is static.

Parameters:

Parameter Type Description
$headers string Raw headers
$count int Redirection count. Default to 1.


Automatically generated on 2025-03-18