Skip to content

Rule Syntax

Yòmá edited this page Dec 29, 2022 · 22 revisions

URI

        userinfo       host      port
        ┌──┴───┐ ┌──────┴──────┐ ┌┴┐
https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top
└─┬─┘   └───────────┬──────────────┘└───────┬───────┘ └───────────┬─────────────┘ └┬┘
scheme          authority                  path                 query           fragment
scheme         = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
authority      = [ userinfo "@" ] host [ ":" port ]
userinfo       = *( unreserved / pct-encoded / sub-delims / ":" )
host           = IP-literal / IPv4address / reg-name
IP-literal     = "[" ( IPv6address / IPvFuture  ) "]"
IPvFuture.     = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
IPv4address.   = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet      = DIGIT                 ; 0-9
               / %x31-39 DIGIT         ; 10-99
               / "1" 2DIGIT            ; 100-199
               / "2" %x30-34 DIGIT     ; 200-249
               / "25" %x30-35          ; 250-255
reg-name       = *( unreserved / pct-encoded / sub-delims )

Basic

field-line     = field-name ":" OWS field-value OWS
field-name     = token
field-value    = *field-content
field-content  = field-vchar
                 [ 1*( SP / HTAB / field-vchar ) field-vchar ]
field-vchar    = VCHAR / obs-text
obs-text       = %x80-FF
token          = 1*tchar
tchar          = "!" / "#" / "$" / "%" / "&" / "'" / "*"
               / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
               / DIGIT / ALPHA
               ; any VCHAR, except delimiters
path-absolute  = "/" [ segment-nz *( "/" segment ) ] ; begins with "/" but not "//"
segment        = *pchar
segment-nz     = 1*pchar
pchar          = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved     = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded    = "%" HEXDIG HEXDIG
sub-delims     = "!" / "$" / "&" / "'" / "(" / ")"
               / "*" / "+" / "," / ";" / "="
OWS            = *( SP / HTAB ); optional whitespace
RWS            = 1*( SP / HTAB ); required whitespace
BWS            = OWS; "bad" whitespace
CR             = %x0D; carriage return
LF             = %x0A; linefeed
CRLF           = CR LF; Internet standard newline
DIGIT          = %x30-39; 0-9
HEXDIG         =  DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
ALPHA          = %x41-5A / %x61-7A; A-Z / a-z
OCTET          = %x00-FF; 8 bits of data
SP             = %x20
HTAB           = %x09; horizontal tab
VCHAR          = %x21-7E; visible (printing) characters
WSP            = SP / HTAB; white space

HTTP Request

HTTP-message   = start-line CRLF
                 *( field-line CRLF )
                 CRLF
                 [ message-body ]
start-line     = request-line / status-line
request-line   = method SP request-target SP HTTP-version
method         = token
request-target = origin-form       ; ( only this form we supported )
               / absolute-form
               / authority-form
               / asterisk-form
origin-form    = absolute-path [ "?" query ]
absolute-path  = 1*( "/" segment )
HTTP-version   = HTTP-name "/" DIGIT "." DIGIT
HTTP-name      = %s"HTTP"
status-line    = HTTP-version SP status-code SP [ reason-phrase ]
status-code    = 3DIGIT
reason-phrase  = 1*( HTAB / SP / VCHAR / obs-text )
message-body   = *OCTET
Transfer-Encoding = #transfer-coding; gzip, chunked

chunked

chunked-body   = *chunk
                 last-chunk
                 trailer-section
                 CRLF
chunk          = chunk-size [ chunk-ext ] CRLF
                 chunk-data CRLF
chunk-size     = 1*HEXDIG
last-chunk     = 1*("0") [ chunk-ext ] CRLF
chunk-data     = 1*OCTET ; a sequence of chunk-size octets
chunk-ext      = *( BWS ";" BWS chunk-ext-name
                 [ BWS "=" BWS chunk-ext-val ] )
chunk-ext-name = token
chunk-ext-val  = token / quoted-string
trailer-section= *( field-line CRLF )

CGI Response

generic-response         = 1*header-field NL [ response-body ]
CGI-Response             = document-response | local-redir-response
                         | client-redir-response | client-redirdoc-response
document-response        = Content-Type [ Status ] *other-field NL
                           response-body
local-redir-response     = local-Location NL
client-redir-response    = client-Location *extension-field NL
client-redirdoc-response = client-Location Status Content-Type *other-field NL
                           response-body

CGI BNF

header-field    = CGI-field | other-field
CGI-field       = Content-Type | Location | Status
other-field     = protocol-field | extension-field
protocol-field  = generic-field
extension-field = generic-field
generic-field   = field-name ":" [ field-value ] NL
field-name      = token
field-value     = *( field-content | LWSP )
field-content   = *( token | separator | quoted-string )
Content-Type    = "Content-Type:" media-type NL
    CONTENT_TYPE = "" | media-type
    media-type   = type "/" subtype *( ";" parameter )
    type         = token
    subtype      = token
    parameter    = attribute "=" value
    attribute    = token
    value        = token | quoted-string
Location        = local-Location | client-Location
client-Location = "Location:" fragment-URI NL
local-Location  = "Location:" local-pathquery NL
fragment-URI    = absoluteURI [ "#" fragment ]
fragment        = *uric
local-pathquery = abs-path [ "?" query-string ]
abs-path        = "/" path-segments
path-segments   = segment *( "/" segment )
segment         = *pchar
pchar           = unreserved | escaped | extra
extra           = ":" | "@" | "&" | "=" | "+" | "$" | ","
Status          = "Status:" status-code SP reason-phrase NL
status-code     = "200" | "302" | "400" | "501" | extension-code
extension-code  = 3digit
reason-phrase   = *TEXT
response-body   = *OCTET
OCTET         = <any 8-bit byte>
CHAR          = alpha | digit | separator | "!" | "#" | "$" |
                "%" | "&" | "'" | "*" | "+" | "-" | "." | "`" |
                "^" | "_" | "{" | "|" | "}" | "~" | CTL
CTL           = <any control character>
SP            = <space character>
HT            = <horizontal tab character>
NL            = <newline>
LWSP          = SP | HT | NL
separator     = "(" | ")" | "<" | ">" | "@" | "," | ";" | ":" |
                "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{" |
                "}" | SP | HT
token         = 1*<any CHAR except CTLs or separators>
quoted-string = <"> *qdtext <">
qdtext        = <any CHAR except <"> and CTLs but including LWSP>
TEXT          = <any printable character>

Clone this wiki locally