eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'HTTPInterface':

Home

everywhere
www.exept.de
for:
[back]

Class: HTTPInterface


Inheritance:

   Object
   |
   +--HTTPInterface

Package:
stx:goodies/communication
Category:
Net-Communication-HTTP-Client
Version:
rev: 1.163 date: 2010/04/26 13:26:38
user: fm
file: HTTPInterface.st directory: goodies/communication
module: stx stc-classLibrary: communication
Author:
Claus Gittinger

Description:


An HTTP Interface (i.e. a client) which is able to fetch documents using
HTTP-Get, Head and Post commands.

- can use HTTP-0.9, HTTP-1.0 or HTTP-1.1 (default)
    HTTP-1.1 is defined in RFC2068.
- keeps track of open socket connections and can keep busy connections open.
- long contents (with configurable size limit) are stored into a temporary file
  and the fileName is provided instead of the contents.
  This is useful if huge files are to be transferred.

Caveat:
    I cannot guarantee, that all HTTP-1.1 features are correctly implemented (as usual).
    However, it seems to work for our applications.



[class variables:]
    USEREL0_9                               - if true, HTTP-0.9 protocol is used
    USEREL1_0                               - if true, HTTP-1.0 protocol is used
                                              if both are false, HTTP-1.1 is used.

    Logging                                 - if true, protocol info is sent to Transcript

    TransferInformationSignal               - raised to pass transfer information; param is ascii-text telling
                                              caller what is currently been done (connecting etc.)
                                              Can be used by GUI to show connection state.

    TransferProgressNotificationSignal      - raised to pass transfer information; param is percentage of xferred data
                                              Can be used by GUI to show progress info.

    UnsupportedOperationNotificationSignal  - http server does not support operation
    ContentTypeInformationSignal            - content-type of document as about to be xferred.
    WrongContentTypeNotificationSignal      - content of document is not as specified in allowedMimeTypes arg.
                                              If proceeded, the document is xferred as usual.
    TransferTimeoutNotificationSignal       - xfer timeout
    ShortTransferNotificationSignal         - short document
    CookieStoreRequestSignal                - http server want to install a cookie

    DefaultTransferTimeout                  - various defaults.
    KeepAliveConnections
    MaxNumberOfKeptConnections


Related information:

    HTTPServer
    HTTPService
    http://www.w3.org/Protocols/rfc2616/rfc2616.html

Class protocol:

Signal constants
o  contentTypeInformationSignal

o  cookieStoreRequestSignal

o  shortTransferNotificationSignal

o  transferInformationSignal

o  transferProgressNotificationSignal

o  transferTimeoutNotificationSignal

o  unsupportedOperationNotificationSignal

o  wrongContentTypeNotificationSignal

debugging
o  logging: aBoolean

defaults
o  defaultConnectTimeout

o  defaultConnectTimeout: seconds

o  defaultTransferTimeout

o  defaultTransferTimeout: seconds

o  maxContentsLengthForDirectData
if a files size is smaller than the value returned by this method, then a bytearray-buffer
is used for the data; otherwise, the data is stored in a temporary file and
the dataFile is passed in the response object.

o  maxNumberOfKeptConnections

o  maxNumberOfKeptConnections: numKept

o  returnCodes

helpers
o  extractCharSetEncodingFromContentType: arg

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

o  extractMimeTypeFromContentType: arg

initialization
o  closeKeptConnections

o  initialize

instance creation
o  connectTo: hostName port: portNrOrNil
create an instance to myself and connect it to portNr on hostName.
If portNr is nil, the default http port will be used.

o  new

o  toHost: hostName port: portNrOrNil
renamed for compatibility with other smalltalks

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

private
o  generateFieldDataFrom: nameValueAssociations

o  multiPartBoundaryPost: url filename: aFilename fileNameFieldName: aFilenameFieldName contents: contents otherValues: aValueDict
a post request with field values in a smalltalk-friendly form

o  request: getOrPost url: urlOrPath fromHost: host port: portNrOrNil accept: acceptedMimeTypes fromDocument: documentURL userName: user password: passwd

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

requests
o  get: url
get url; returns a response-object

o  get: url accept: acceptedMimeTypes
get url, accepting types in acceptedMimeTypes.
Returns a response-object.

o  get: url destinationFile: destinationFilename
get url; returns a response-object. Data is stored in destinationFile

o  get: url fromDocument: referrer
get url; returns a response-object

o  get: path fromHost: host
get path from host.
Returns a response-object.

o  get: path fromHost: host port: portNr
get path from host.
If port is not nil, it is a SmallInteger used instead of the default port.
Returns a response-object.

o  get: path fromHost: host port: portNrOrNil accept: acceptedMimeTypes fromDocument: documentURL
get path from host.
If port is not nil, it is a SmallInteger used instead of the default port.
DocumentUrl may be nil or a String containing the url of the referring document.
Returns a response-object.

o  get: urlOrPath fromHost: host port: portNrOrNil accept: acceptedMimeTypes fromDocument: documentURL userName: user password: passwd
get url from host.
If port is not nil, it is a SmallInteger used instead of the default port.
DocumentUrl may be nil or a String containing the url of the referring document.
Returns a response-object.

o  get: path fromHost: host port: portNrOrNil fromDocument: documentURL
get path from host.
If port is not nil, it is a SmallInteger used instead of the default port.
DocumentUrl may be nil or a String containing the url of the referring document.
Returns a response-object.

o  get: url userName: user password: password
get url; Returns a response-object.

o  get: url with: data
a get request with field values in HTTP-request form (&nameKey=value;).
returns a response-object

o  get: url withFields: nameValueAssociations
a get request with field values.
returns a response-object

o  getFile: url
a get request, returning the data if present, or else raising an error.

o  multiPartBoundaryPost: url fromHost: host port: port userName: userName password: password attributes: aValueDict
a post request with field values in a smalltalk-friendly form

o  post: url with: data
a post request with field values in HTTP-request form (&nameKey=value;)

o  post: url withFields: nameValueAssociations

o  request: getOrPost url: urlOrPathArg fromHost: hostOrNil port: portNrOrNil accept: acceptedMimeTypes fromDocument: documentURL userName: userOrNil password: passwordOrNil contentType: contentType contents: contents
send a get/post request to host.
If port is not nil, it is a SmallInteger used instead of the default port.
DocumentUrl may be nil or a String containing the url of the referring document.
Returns a response-object.

o  request: getOrPost url: urlOrPathArg fromHost: hostOrNil port: portNrOrNil accept: acceptedMimeTypes fromDocument: documentURL userName: userOrNil password: passwordOrNil contentType: contentType contents: contents destinationFile: destinationFilenameOrNil
send a get/post request to host.
If port is not nil, it is a SmallInteger used instead of the default port.
DocumentUrl may be nil or a String containing the url of the referring document.
Returns a response-object.

validation
o  validateAStringOnW3Org: aString


Instance protocol:

accessing
o  acceptedCharsets

o  acceptedCharsets: something

o  acceptedEncodings

o  acceptedEncodings: something

o  acceptedLanguages

o  acceptedLanguages: something

o  acceptedMimeTypes

o  acceptedMimeTypes: something

o  additionalHeaderLines

o  additionalHeaderLines: something

o  connectTimeout

o  connectTimeout: something
set the connectionTimeout in seconds

o  contentType

o  contentType: something

o  contents

o  contents: something

o  destinationFile: aFilename
if given, received data will be stored there, instead of being returned
as string/byteAray. use this for bug file transfers

o  maxContentsLengthForDirectData: anInteger
if given, that is the maximum size of received data to be returned directly as
ByteArray/String. If the received document is larger, it will be stored into a
tempfile and that file's name is found in the dataFile slot of the response data.
If left undefined, a default value (currently 4Mb) is used as a maximum

o  password

o  password: something

o  referer

o  referer: something

o  socket

o  socket: aSocket

o  suppressUnicode: aBoolean

o  transferTimeout

o  transferTimeout: seconds
set the transferTimeout in seconds

o  userAgent

o  userAgent: something

o  userName

o  userName: something

helpers
o  acceptString: aStringOrCollection for: what

o  authenticationStringForUser: user password: passwd

o  close

o  closeSocket

o  decodeData: data forMimeType: mimeType andEncoding: encoding into: aResponse

o  doRequest
send a request and expect response. return nil or a response.
The retrieved data is provided as:
- destinationFile's contents, if a destinationFile was given
- direct data (in response data), if the retrieved data is not too big
- a temporary dataFile, for large files.

o  doRequest: getOrPost

o  extractTransferParametersFromInfo: info

o  getResponse

o  logInfo: msg

o  parseInfo: rawHeader into: anHTTPResponse

o  receiveDocument

o  sendData: data

o  socketHandlingAfterRequestWithResponse: responseArg
cache the connection/socket for future requests.
Weather we do caching, depends on the returned HTTP response

o  transferRateStringFor: bytesTransferedPerSecond

initialization
o  connectTo: hostName port: portNrOrNil

o  connectTo: hostName port: portNrOrNil useSSL: useSSL

o  initialize

o  toHost: hostName port: portNrOrNil
renamed for compatibility with other smalltalks

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

queries
o  dataBufferSize

o  isConnected

release
o  destroy

requests
o  request: getOrPost url: urlArg

o  requestDELETE: args url: urlArg

o  requestGET: urlArg

o  requestHEAD: urlArg

o  requestPOST: args url: urlArg

o  requestPUT: args url: urlArg

requests - obsolete backward compatibility
o  request: getOrPost url: urlArg acceptedEncodings: acceptedEncodingsArg acceptedLanguages: acceptedLanguagesArg acceptedCharsets: acceptedCharsetsArg acceptedMimeTypes: acceptedMimeTypesArg additionalHeaderLines: additionalHeaderLinesArg contentType: contentTypeArg contents: contentsArg from: currentURL

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

o  request: getOrPost url: urlArg acceptedEncodings: acceptedEncodingsArg acceptedLanguages: acceptedLanguagesArg acceptedCharsets: acceptedCharsetsArg acceptedMimeTypes: acceptedMimeTypesArg additionalHeaderLines: additionalHeaderLinesArg contentType: contentTypeArg contents: contentsArg from: refererArg userName: userNameArg password: passwordArg

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

o  request: getOrPost url: urlArg acceptedEncodings: acceptedEncodingsArg acceptedLanguages: acceptedLanguagesArg acceptedCharsets: acceptedCharsetsArg acceptedMimeTypes: acceptedMimeTypesArg from: refererArg

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

o  request: getOrPost url: urlArg acceptedEncodings: acceptedEncodingsArg acceptedLanguages: acceptedLanguagesArg acceptedCharsets: acceptedCharsetsArg acceptedMimeTypes: acceptedMimeTypesArg from: refererArg userName: userNameArg password: passwordArg

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

o  requestGET: url accept: acceptedMimeTypes

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

o  requestGET: url accept: acceptedMimeTypes from: currentURL

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

o  requestGET: url accept: acceptedMimeTypes from: currentURL userName: user password: passwd

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

o  requestGET: urlArg from: refererString

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


Private classes:

    HTTPResponse
    KeptSocketInfo
    TransferProgressNotificationSignal
    TransferTimeoutNotificationSignal

Examples:



    |rply document|

    rply := HTTPInterface get:'/' fromHost:'www.exept.de'.
    (rply notNil and:[rply isErrorResponse not]) ifTrue:[
        document := rply data asString.
        HTMLDocumentView openOnText:document.
    ]


    |rply document|

    rply := HTTPInterface get:'/' fromHost:'www.altavista.com'.
    (rply notNil and:[rply isErrorResponse not]) ifTrue:[
        TextBox openOn:(rply data asString)
    ]


    |rply document|

    rply := HTTPInterface get:'/' fromHost:'www.microsoft.com'.
    (rply notNil and:[rply isErrorResponse not]) ifTrue:[
        TextBox openOn:(rply data asString)
    ]


     |h reply|

     h := HTTPInterface toHost:'localhost' port:8080.
     (h requestGET:'/') inspect.
     h closeSocket.


    |rply document|

    rply := HTTPInterface get:'/' fromHost:'www.exept.de' port:(Socket portOfService:'https').
    (rply notNil and:[rply isErrorResponse not]) ifTrue:[
        document := rply data asString.
        HTMLDocumentView openOnText:document.
    ]


ST/X 6.1.1; WebServer 1.620 at exept:8081; Mon, 21 May 2012 17:47:00 GMT