eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'HTTPRequest':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: HTTPRequest


Inheritance:

   Object
   |
   +--HTTPRequest
      |
      +--FCGIRequest

Package:
stx:goodies/webServer
Category:
Net-Communication-HTTP-Server
Version:
rev: 1.261 date: 2019/03/13 19:15:48
user: stefan
file: HTTPRequest.st directory: goodies/webServer
module: stx stc-classLibrary: webServer
Author:
Christian Penk

Description:


represents an HTTP request as received by the HTTPServer.


[instance variables:]
    server              the server from which this request was received
    connection          the socket conection from which this request was received
    peer                the sender of this request
    peerName

    rawRequestString:   the whole request incl. any POST-data (required for com-swiki)
    rawHeader           the raw http-header (without data)
    headerDictionary    extracted fields
    headerLines         header lines
    method              ?
    httpVersion         httpVersion from the header
    url                 the requests original url
    postDataFields      POST request arguments
    urlParameters       &-parameters as extracted from the URL
    contentLength       contentLength from the header
    contentType         contentType from the header
    contentEncoding     contentEncoding from the header
    connectionAttributes     connectionAttributes from the header (Keep/close etc.)
    userAgent           userAgent from the header (IE, mozilla etc.)
    authorization       authorization from the header
    acceptedTypes       acceptedTypes from the header
    acceptedEncodings   acceptedEncodings from the header
    acceptedCharsets    acceptedCharsets from the header
    acceptedLanguages   acceptedLanguages from the header
    referer             referrer from the header 
                        (notice the misspelling due to the misspelling in HTTP - see RFC)
    host                host from the header
    soapAction          soapAction from the header
    cookies             cookies from the header

    data                the POST-data alone
    postData            ?
    userId              ?
    serviceLinkName     ?
    service             ?
    relativePath        URL relative to service-linkName
    message             the original message; split and preparsed
    arguments           additional arguments for object-requests (preparsed from the url)
    selector            ?
    multipartBoundary   ?
    multiPartChunks     ?
    queryString         url parameters - rest after any in { & ; ? }
    response            response object


Related information:

    http://www.w3.org/Protocols/rfc2616/rfc2616.html
    HTTPResponse
    HTTPServer
    HTTPInterface

Class protocol:

defaults
o  allowedRequestMethods

header parsing
o  extractCookiesFrom: line
now done lazy, when the value is asked for;

helpers
o  extractAcceptedFromLine: acceptLine
self extractAccepted:'accept:' fromLine:'image/gif, image/x-xbitmap;q=0.2, image/jpeg, image/pjpeg, image/png, */*;q=0'


self extractAccepted:'accept:' fromLine:'text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5'
should cause the following values to be associated:

text/html;level=1 = 1
text/html = 0.7
text/plain = 0.3

image/jpeg = 0.5
text/html;level=2 = 0.4
text/html;level=3 = 0.7


o  extractMultipartBoundaryFromContentType: contentTypeLine

instance creation
o  server: httpServer connection: connection

serving-helpers
o  controlCharacters

o  escape: arg

o  escapeCharacterEntities: arg

o  unEscape: arg

o  urlEncoded: arg


Instance protocol:

accessing
o  arguments
the arguments of a SelectorService

o  authenticator

o  authenticator: something

o  connection
return the connection from which this request came

o  multiPartChunks

o  pathRelativeToService
set the path relative to the services root path.
- without a leading /

o  pathRelativeToService: aString
set the path relative to the services root path.
- without a leading /

o  queryString

o  rawUrl

o  rawUrl: something

o  relativePath
Obsolete: use #pathRelativeToService.
get the path relative to the services root path.
- with a leading /

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  replyPresenter

o  response

o  selector
the selector of a SelectorService

o  service

o  service: serviceArg serviceLinkName: serviceLinkNameArg

o  serviceRequestContext

o  serviceRequestContext: something

accessing-http request data
o  cookiesAt: aString
Selects all the cookies with the name aString.
<return: Collection>

o  data

o  getURLQueryString

o  hasUrlParameter: key
true, if key is present in the url-param (after the urls path, separated by &'s)

o  multiPartChunkDataAt: key

o  multiPartChunkDataAt: key ifAbsent: replacement

o  multiPartChunkFilenameAt: key

o  multiPartChunkFilenameAt: key ifAbsent: aBlock

o  peer
get the peer (ip-address) of the connection from which this request came from

o  peer: something
set the value of the instance variable 'peer' (automatically generated)

o  peerName
get the hostname of the requestor from which this request came from

o  peerName: something
set the value of the instance variable 'peerName' (automatically generated)

o  postData
get the post data (if any)

o  postDataFieldAt: key
a field (typically of a POST request)

o  postDataFieldAt: key ifAbsent: replacement
a field (typically of a POST request)

o  postDataFields
the fields (typically of a POST request).
Nil if there are none.

o  postDataVectorAt: key
all url parameters for key (after the urls path, separated by &'s)

o  postDataVectorAt: key ifAbsent: replacement
all url parameters for key (after the urls path, separated by &'s)

o  rawRequestString

o  realPeer
get the real peer (ip-address) of the connection from which this request came from.
This takes possible proxies into account.

o  selector: selectorArg arguments: argumentsArg
remember selector and arguments of a SelectorService (for the service)

o  server

o  serverHostName

o  serviceLinkName

o  serviceLinkName: something

o  socketAddress
answer the address that received the request.
This is one of the addresses assigned to the server

o  urlParameterAt: key
a scalar url-param (after the urls path, separated by &'s).
For example, if the url is 'foo?bar=1?baz=2', then
urlParameterAt:'bar'
would return '1' (a string)

o  urlParameterAt: key ifAbsent: replacement
a scalar url-param (after the urls path, separated by &'s)

o  urlParameterAt: key put: aString

o  urlParameterVectorAt: key
all url parameters for key (after the urls path, separated by &'s)

o  urlParameterVectorAt: key ifAbsent: replacement
all url parameters for key (after the urls path, separated by &'s)

o  urlParameters
the url-params (after the urls path, separated by &'s).
Nil if there are none.

o  valueOfNumericPostDataField: fieldName

accessing-http request header
o  acceptedCharsets
as extracted from the http-header,
returns key-value associations

o  acceptedEncodings
as extracted from the http-header

o  acceptedLanguages
return the value of the instance variable 'acceptedLanguages' (automatically generated)

o  acceptedTypes
as extracted from the http-header, if no Accept: field is present,
then it is assumed that text/plain and text/html are accepted.

usage example(s):

acceptedTypes := #('text/plain' 'text/html').

o  authorizationHeader
as extracted from the http-header

o  connectionAttributes
return the connection's attributes

o  contentEncoding
return the content-encoding (charset) value from the header (if present)

o  contentLength
return the value of the instance variable 'contentLength' (automatically generated)

o  contentType
return the content-type (mime) field from the header (if present)

o  cookies
return the cookies sent with the request (if any)

o  fieldValueFor: aFieldKey

o  fieldValues
answer all the header fields as a Dictionary

o  header
the header as a dictionary

o  headerFieldValueFor: keyword

o  host
get the header's host field (not really trustable)

o  httpVersion

o  ifModifiedSince
the file should be sent if modified after this date.
Otherwise reponseCode 304 Not Modified may be send.

o  method
return the method of this request (GET, POST, PUT, HEADER or DELETE)

o  method: aString

o  multipartBoundary

o  rawHeader

o  referer
yes, I know that 'referer' is a misspelling of 'referrer'.
However, somehow it made it into the HTTP standard, and is called 'referer' there - sigh.
So keep this name and also the string below

o  referrer
the referring page - if known.
Notice the misspelling below - due to the fact that the misspelling made it into
the HTTP standard.
So keep the string below

o  soapAction

o  url

o  userAgent

accessing-http response data
o  binary: aBoolean
set/clear binary mode in the response (data is bytes as opposed to text)

o  expirationTime: aTimeStamp
the responses expirationTimestamp; consider to use response maxAge:

o  replyData: aStringOrBytes
set the reply data

o  replyHeader
return the value of the instance variable 'replyHeader' (automatically generated)

o  resetResponseData
start anew collecting response data
(i.e. throw away what has been already collected)

o  responseContentType: something
set the value of the instance variable 'contentType' (automatically generated)

accessing-sessions
o  getSession

o  getSession: shouldCreateIfNone

o  getSession: shouldCreateIfNone forceLinkName: aLinkName
Get the current valid session associated with the request.
If shouldCreateIfNone is true then either a new session will be created
or the current one will be returned if one exists.
Answer nil, if shouldCreateIfNone is false and there is no session.

The session's scope is a single service (over all of its possible linkNames).

<return: HTTPSession | nil>

authentication
o  authenticateForRealm: aRealm
authenticate myself for a realm.
Raise an error, if authentication fails

o  authenticatedUsername
get the user, that has been authenticated
or nil, if there is none

o  isForbiddenUserAgent: aUserAgentString
are there user agents which we definitely do not want in our house?

error reporting
o  reportBadRequest: msg
bad request.
This method will not return (i.e. aborts).

o  reportException: ex
Write an error report.
This method will not return (i.e. aborts).

o  reportForbidden: msg
access forbidden.
This method will not return (i.e. aborts).

o  reportForbidden: msg info: infoText
access forbidden.
This method will not return (i.e. aborts).

o  reportHTTPVersionNotSupported: msg
This method will not return (i.e. aborts).

o  reportMethodNotAllowed: msg method: badMethod url: badURL
method (such as POST, PUT etc.) is not allowed.
This method will not return (i.e. aborts).

o  reportMovedPermanently: newUrl
page has been permanently moved to another location, newUrl.
This method will not return (i.e. aborts).

o  reportNotAcceptable: typeAvailable
not acceptable - content-type not in accept list.
This method will not return (i.e. aborts).

o  reportNotFound: msg
document/object was not found.
This method will not return (i.e. aborts).

Take care: IE6 will not show this message, but its own message,
if the whole repsonse is shorter than 512 bytes and
'Show Short HTTP Error Messages' is on in Internet Settings

o  reportNotFound: msg moreInfo: moreInfoText
document/object was not found.
This method will not return (i.e. aborts).

Take care: IE6 will not show this message, but its own message,
if the whole repsonse is shorter than 512 bytes and
'Show Short HTTP Error Messages' is on in Internet Settings

o  reportRequestTimeout: message
request timeout - the request was transmitted too slowly.
This method will not return (i.e. aborts).

o  reportServerError: msg moreInfo: aStringOrNil
server error.
This method will not return (i.e. aborts).

o  reportServiceUnavailable: msg
report temporary down.
This method will not return (i.e. aborts).

o  reportUnauthorized: messageText
no authorization - ask for authorization.
This method will not return (i.e. aborts).

o  reportUnsupportedFeature: msg
bad request.
This method will not return (i.e. aborts).

o  sendErrorResponseForResponseCode: aStatusCode

o  sendErrorResponseForResponseCode: aStatusCode body: bodyText
not reached

o  sendErrorResponseForResponseCode: aStatusCode message: messageString
Send an error for aStatusCode (e.g. 440 - Not found).
messageString may contain additional information

o  sendErrorResponseForResponseCode: aStatusCode title: titleText body: bodyText
abort processing request - do not close socket in exception handler

o  sendErrorResponseForStatusCode: aStatusCode

o  sendErrorResponseForStatusCode: aStatusCode body: bodyText

header parsing
o  extractCookiesFrom: arg

o  headerParser

o  parseFirstLine
parse the line consisting of GET/HEAD/POST <url> <httpVersion>

o  parseHeader
parse the first header line now - the rest is parsed on demand

o  rawRequestString: rawRequestStringArg rawHeader: rawHeaderArg data: dataArg
MessageTally spyDetailedOn:[

html reply composition-stream protocol
o  nextPutAll: aString
append aString to the collected reply.

o  nextPutAllEscaped: aString
append aString to the collected reply.
The string is processed, by replacing html-special characters by there html-equivalent (such as '>' into &lt;)

o  nextPutLine: aString
append aString to the collected reply and append a lineBreak.

o  nextPutLineEscaped: aString
append aString to the collected reply and append a cr.
The string is processed, by replacing html-special characters by there html-equivalent (such as '>' into &lt;)

logging
o  logAccess

o  logError: aString

misc
o  environmentValueFor: aFieldKey
return the value of an environment value.
We have none, so return nil here. This is defined for FastCGI compatibility

obsolete
o  escape: aString
use class escape:

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  unEscape: aString
use class unEscape:

** This is an obsolete interface - do not use it (it may vanish in future versions) **

old html reply composition
o  bodyEnd
Write </BODY>.
OLD stuff - please use a TreeBuilder

o  bodyStart
Write <BODY>.
OLD stuff - please use a TreeBuilder

o  formEnd
append the standard footer for a form.
OLD stuff - please use a TreeBuilder

o  formFooter
Write the standard footer for a form.
OLD stuff - please use a TreeBuilder

o  formResetButton
generate a reset button for a form.
OLD stuff - please use a TreeBuilder

o  formSubmitButton
OLD stuff - please use a TreeBuilder

o  formSubmitButtonForString: aString
OLD stuff - please use a TreeBuilder

o  formSubmitButtonForString: aString name: aName
OLD stuff - please use a TreeBuilder

o  formSubmitButtonStringForString: aString name: aName
OLD stuff - please use a TreeBuilder

o  htmlEnd
OLD stuff - please use a TreeBuilder

o  htmlStart
OLD stuff - please use a TreeBuilder

o  imageFor: anImageOrImageFilename
generate an IMG tag for a real image (or an image file name).
OLD stuff - please use a TreeBuilder

o  imageFor: anImageOrImageFilename alt: alt
an IMG tag for a real image (or an image file name).
OLD stuff - please use a TreeBuilder

o  imageLinkTextFor: anImageOrImageFilename alt: alt
return an IMG tag for a real image (or an image file name).
OLD stuff - please use a TreeBuilder

o  inputFieldFor: varName label: label initialValue: value
an input field - must be within a form.
OLD stuff - please use a TreeBuilder

o  inputFieldFor: varName size: size label: label initialValue: value
an input field - must be within a form.
OLD stuff - please use a TreeBuilder

o  inputFieldFor: varName type: aType size: size label: label initialValue: value
an input field - must be within a form.
OLD stuff - please use a TreeBuilder

o  inputFieldFor: varName type: aType size: size label: label initialValue: value append: aString
an input field - must be within a form.
type: 'password' | 'checkbox' | 'submit' | 'reset' | nil

o  inputFieldStringFor: varName type: aType size: size label: label initialValue: value append: aString
an input field - must be within a form.
type: 'password' | 'checkbox' | 'submit' | 'reset' | nil

o  label: labelString id: idString value: anObject
Add a table row for the given data to the reply.

o  label: labelString text: aString id: idString rows: rows cols: cols
Build a textarea form field.

o  refreshStringFor: aService selector: aSelector arguments: arguments time: seconds
OLD stuff - please use a TreeBuilder

o  refreshStringFor: aService selector: aSelector time: seconds
OLD stuff - please use a TreeBuilder

o  table: aBlock
OLD stuff - please use a TreeBuilder

o  table: aBlock attributes: attrString
OLD stuff - please use a TreeBuilder

o  tableEnd
OLD stuff - please use a TreeBuilder

o  tableFormFooter
Close the table and write the standard footer for a form.

o  tableRow: aBlock
OLD stuff - please use a TreeBuilder

o  tableRow: aBlock attributes: attrString
OLD stuff - please use a TreeBuilder

o  tableRowEnd
OLD stuff - please use a TreeBuilder

o  tableRowStart: attrString
OLD stuff - please use a TreeBuilder

o  tableStart: attrString
OLD stuff - please use a TreeBuilder

o  title: aString
Write a standard header and set the document title.

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  title: aString with: someMoreHeaderStuff
Write a standard header and set the document title. Also used for logging purposes.

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  titleAndHeader: aString
Write a standard header and set the document title.

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  unformattedCodeTextEnd
end some plainText.

o  unformattedCodeTextStart
start some plainText.

o  unformattedText: aString
add some plainText.

o  unformattedTextEnd
end some plainText.

o  unformattedTextStart
start some plainText.

old html reply composition stx
o  pageFinish
finish the page.

o  pageSTXFooter
Write the standard page footer.

o  stxBodyEnd

o  stxBodyStart: aString
Write a standard stx body with a headline #f6feff

o  stxBodyStart: aString homeLink: aHomeLink
Write a standard stx body with a headline #f6feff

o  stxBodyStart: aString homeLink: aHomeLink afterButtons: afterButtonsString
Write a standard stx body with a headline #f6feff

o  stxPageFinish
finish the page.

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  stxPageParameters

o  stxPoweredByString

o  stxReply: aString

old links-html generation
o  homeWebLinkForText: nameString
Return HTML code for a link to anObject using the given name and message selector.

o  linkIdFor: aService
Return the linkId to send aMessage to anObject.
if the request is for another service, answer the first link for the service

o  linkIdFor: aService argument: argumentString
Return the linkId to send aMessage to anObject.
Create a new linkId if necessary.

o  linkIdFor: aService selector: aSelector
Return the linkId to send aMessage to anObject.
Create a new linkId if necessary.

o  linkIdFor: aService selector: aSelector argument: argumentString
Return the linkId to send aMessage to anObject.
Create a new linkId if necessary.

o  webLinkForImage: imageOrImageFilename service: aService argument: aSelector
Return HTML code for a link to anObject using the given name and message selector.

o  webLinkForImage: imageOrImageFilename service: aService selector: aSelector
Return HTML code for a link to anObject using the given name and message selector.

o  webLinkForText: nameString link: aLinkId
Return HTML code for a linkId using the given name
and message selector. When the link is followed,
aSelector plus argument will be sent to anObject.

o  webLinkForText: nameString service: aService argument: anArgument
Return HTML code for a link to aService using the given nameString
and aSelector. When the link is followed,
aSelector plus argument will be sent to aService.

o  webLinkForText: nameString service: aService selector: aSelector
Return HTML code for a link to anObject using the given name and message selector.

o  webLinkForText: nameString service: aService selector: aSelector argument: anArgument
Return HTML code for a link to aService using the given nameString
and aSelector. When the link is followed,
aSelector plus argument will be sent to aService.

o  webLinkText: nameString target: targetString service: aService selector: aSelector
Return HTML code for a link to aService using the given name and message selector.

printing
o  printOn: aStream
(comment from inherited method)
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.

The default here is to output the receiver's class name.
BUT: this method is heavily redefined for objects which
can print prettier.

queries
o  closeConnectionAfterError
Answer true, if the connection should be closed when the request resulted in
an error. To avoid getting hogged down by a bad guy, limit his access speed,
by closing the connection.
But keep connection, if we did refer to the bad page.

o  fullPath
return the full path from this requrest's URL

o  isDELETE
return true, if the request was a DELETE request

o  isGET
return true, if the request was a GET request

o  isHEAD
return true, if the request was a HEAD request

o  isOPTIONS
return true, if the request was an OPTIONS request

o  isPOST
return true, if the request was a POST request

o  isPUT
return true, if the request was a PUT request

o  isReferredFromOwnHost
answer true, if this request is referred to from my own host.
This cannot be reliably trusted, since the client can send any referrer.

o  isSecure
answer true, if this request was issued over an secure channel (SSL/TLS)

o  startReadRequestTime

o  timeToPerform
in milliseconds

response collecting
o  addCookie: cookie
send a cokkie with the response.
Remember the cookie in the request, so that session cookies
will not be created twice

o  addToReplyHeader: aString
collect part of a header (i.e. append aString to the reply header).

o  reply: aString
collect part of a reply (i.e. append aString to the reply buffer).

o  reply: aString with: aParameter
collect part of a reply (i.e. append aString to the reply buffer);
aString may contain %1 escape which is replaced by aParameter.

o  replyCR
Append a cr to the reply buffer

o  replyEscaped: aStringOrCharacter
collect part of a reply (i.e. append aString to the reply buffer).
Special character (lt, gt) are escaped.

o  replyHeader: aString
set the reply header

o  replyURLEscaped: aStringOrCharacter
collect part of a reply (i.e. append aString to the reply buffer).
URL-Special characters (&, space etc.) are escaped.

response sending
o  redirectTo: link
redirect both per META and per 302-location-redirect.
(because content-location redirection doesn't work for most of the browsers)

o  sendBinary: aStreamOrBytes type: contentType
send some binary data as a response.
Typically used with images and non-text documents

o  sendBinaryData: binaryData type: contentType
send some binary data as a response.
Typically used with images and non-text documents

o  sendBinaryStream: aStreamOrBytes type: contentType
send some binary data as a response.
Typically used with images and non-text documents

o  sendImage: inImage
reply with a bitmap image.
For now, must send it as gif ... (could do jpg as well),
or even better, remember what types are supported by the browser

o  sendImage: inImage type: imageType
reply with a bitmap image.
For now, must send it as gif ... (could do jpg as well),
or even better, remember what types are supported by the browser

o  sendResponse
send the response

o  sendResponseWithType: aContentType
send the response

serving-helpers
o  checkAcceptableType: type
correspondingQ := eachAcceptedTypeAndQPair value.

o  decodeFields: aString
Convert the form fields in Collection of strings into a dictionary.
collection is needed because e.g. (on <SELECT name=FOO MULTIPLE> by client selects more than one
FOO comes with same key and different values)
Each field should be of the form: &nameKey=collection of values

o  extractPostDataFields
split at CRLFCRLF (left part are fields; right part is data)

o  extractURLParametersFromPath: path
answer the local part of the path without parameters.
As a side effect the parameters are stored in the instVar urlParameters

serving-processing
o  handleSOAPAction
reply with permission denied

o  reprocess
reproces the current request (see handler in generateReply)

o  reprocessWithInternalURL: aNewInternalURL
reproces the current request with another URL (see handler in generateReply)

o  reprocessWithServiceURL: aNewInternalServiceURL

o  robotPolicy
Return a text specifying our robots policy.
This is the answer to be given to webCrawlers and tells them,
which URLs (subtrees) should not be visited.
See
http://info.webcrawler.com/mak/projects/robots/norobots.html
for details.
The default here is to disallow everything.

o  url: aNewURL

serving-requests
o  generateReply
handle a request; generate the reply.

o  generateReplyForDeleteRequest
handle a delete-request; generate the reply.

o  generateReplyForGetRequest
Generate the reply to a GET request.

o  generateReplyForHeadRequest
Generate the reply to a HEAD request (same as GET, but no data is sent at the end).

o  generateReplyForOptionsRequest
handle an options-request; generate the reply.

o  generateReplyForPostRequest
handle a post-request; generate the reply.

o  generateReplyForPutRequest
handle a put-request; generate the reply.

serving-serverState
o  checkMaintenanceMode
if server is in mainenance mode, no files are served to normal users.
Access to a server in maintenance mode is only possibly to a user
that has authenticated for maintenance service

setup from connection
o  initializeForServer: serverArg connection: connectionArg

o  postData: something


Private classes:

    MultipartChunk
    ReprocessRequest


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Tue, 19 Mar 2024 10:09:36 GMT