-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHasHttpRegex.php
More file actions
69 lines (65 loc) · 2.07 KB
/
HasHttpRegex.php
File metadata and controls
69 lines (65 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php declare(strict_types=1);
namespace Salient\Http;
/**
* @internal
*/
interface HasHttpRegex
{
public const AUTHORITY_FORM_REGEX = '/^(([-a-z0-9!$&\'()*+,.;=_~]|%[0-9a-f]{2})++|\[[0-9a-f:]++\]):[0-9]++$/iD';
public const HOST_REGEX = '/^(([-a-z0-9!$&\'()*+,.;=_~]|%[0-9a-f]{2})++|\[[0-9a-f:]++\])$/iD';
public const HTTP_FIELD_NAME_REGEX = self::HTTP_TOKEN_REGEX;
public const HTTP_FIELD_VALUE_REGEX = '/^([\x21-\x7e\x80-\xff]++(?:\h++[\x21-\x7e\x80-\xff]++)*+)?$/D';
public const HTTP_TOKEN_REGEX = '/^[-0-9a-z!#$%&\'*+.^_`|~]++$/iD';
public const HTTP_TOKEN = '(?:(?i)[-0-9a-z!#$%&\'*+.^_`|~]++)';
public const SCHEME_REGEX = '/^[a-z][-a-z0-9+.]*$/iD';
public const HTTP_FIELD_LINE_REGEX = <<<'REGEX'
/ ^
(?(DEFINE)
(?<token> [-0-9a-z!#$%&'*+.^_`|~]++ )
(?<field_vchar> [\x21-\x7e\x80-\xff]++ )
(?<field_content> (?&field_vchar) (?: \h++ (?&field_vchar) )*+ )
)
(?:
(?<name> (?&token) ) (?<bad_whitespace> \h++ )?+ : \h*+ (?<value> (?&field_content)? ) |
\h++ (?<extended> (?&field_content)? )
)
(?<carry> \h++ )?
$ /ixD
REGEX;
public const URI_REGEX = <<<'REGEX'
` ^
(?(DEFINE)
(?<unreserved> [-a-z0-9._~] )
(?<sub_delims> [!$&'()*+,;=] )
(?<pct_encoded> % [0-9a-f]{2} )
(?<reg_char> (?&unreserved) | (?&pct_encoded) | (?&sub_delims) )
(?<pchar> (?®_char) | [:@] )
)
(?: (?<scheme> [a-z] [-a-z0-9+.]* ) : )?+
(?:
//
(?<authority>
(?:
(?<userinfo>
(?<user> (?®_char)* )
(?: : (?<pass> (?: (?®_char) | : )* ) )?
)
@
)?+
(?<host> (?®_char)*+ | \[ (?<ipv6address> [0-9a-f:]++ ) \] )
(?: : (?<port> [0-9]+ ) )?+
)
# Path after authority must be empty or begin with "/"
(?= / | \? | \# | $ ) |
# Path cannot begin with "//" except after authority
(?= / ) (?! // ) |
# Rootless paths can only begin with a ":" segment after scheme
(?(<scheme>) (?= (?&pchar) ) | (?= (?®_char) | @ ) (?! [^/:]++ : ) ) |
(?= \? | \# | $ )
)
(?<path> (?: (?&pchar) | / )*+ )
(?: \? (?<query> (?: (?&pchar) | [?/] )* ) )?+
(?: \# (?<fragment> (?: (?&pchar) | [?/] )* ) )?+
$ `ixD
REGEX;
}