|
Class: HTTPHeaderParser
Object
|
+--HTTPHeaderParser
- Package:
- stx:goodies/webServer
- Category:
- Net-Communication-HTTP-Server
- Version:
- rev:
1.12
date: 2023/11/29 14:51:17
- user: cg
- file: HTTPHeaderParser.st directory: goodies/webServer
- module: stx stc-classLibrary: webServer
an incremental header parser.
reads just enough from a header to retrieve a given header-key-value.
eg.
|request parser|
request :=
c'NOTIFY * HTTP/1.1\r
Host: 239.255.255.250:1900\r
NT: ssdp:testService\r
NTS: ssdp:alive\r
USN: uuid:2ABD6992-5F53-E257-21DE-37F10950FD0A::exepts-MBP::ssdp:testService\r
Location: http://test.local/\r
Cache-Control: max-age=180\r
\r
\r
'.
parser := HTTPHeaderParser headerString:request.
Transcript showCR:(parser fieldValueFor:'NT').
Transcript showCR:(parser fieldValueFor:'USN').
Transcript showCR:(parser fieldValueFor:'nts').
Transcript showCR:(parser fieldValueFor:'cache-control').
copyrightCOPYRIGHT (c) 2003 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
instance creation
-
headerString: aHeaderString
-
instantiate a new header parser on aHeaderString
accessing
-
headerString
-
-
headerString: aString
-
backward compatibility
-
fieldValueFor: aFieldKey
-
return the value for a header field key or nil if absent.
Use a lowercase key for slightly faster access (but uppercase is now allowed)
-
fieldValueFor: aFieldKey ifAbsent: fallBackValue
-
return the value for a header field key or the value from fallBackValue if absent.
Use a lowercase key for slightly faster access (but uppercase is now allowed)
header line accessing
-
at: aFieldKey
-
return the value for a header field key or nil if absent.
Use a lowercase key for slightly faster access (but uppercase is now allowed)
-
at: aFieldKey ifAbsent: fallBackValue
-
return the value for a header field key or the value from fallBackValue if absent.
Use a lowercase key for slightly faster access (but uppercase is now allowed)
-
fieldValues
-
return all field values as a dictionary, indexed by key
-
startLine
-
return the first line (which contains the request type)
private actions
-
parseHeader
-
parse all header lines and remember as key-value pairs in headerLines
-
parseHeaderForFieldKey: aFieldKey
-
continue parsing lines until aFieldKey is encountered.
Then return that value.
On the fly, remember what has been read so far
queries
-
atEnd
-
CRLF CRLF
-
nextLine
-
Modified (format): / 21-05-2021 / 12:48:08 / cg
|