|
|
Class: HTTPInterface
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
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
HTTPServer
HTTPService
http://www.w3.org/Protocols/rfc2616/rfc2616.html
Signal constants
-
contentTypeInformationSignal
-
-
cookieStoreRequestSignal
-
-
shortTransferNotificationSignal
-
-
transferInformationSignal
-
-
transferProgressNotificationSignal
-
-
transferTimeoutNotificationSignal
-
-
unsupportedOperationNotificationSignal
-
-
wrongContentTypeNotificationSignal
-
debugging
-
logging: aBoolean
-
defaults
-
defaultConnectTimeout
-
-
defaultConnectTimeout: seconds
-
-
defaultTransferTimeout
-
-
defaultTransferTimeout: seconds
-
-
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.
-
maxNumberOfKeptConnections
-
-
maxNumberOfKeptConnections: numKept
-
-
returnCodes
-
helpers
-
extractCharSetEncodingFromContentType: arg
-
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
extractMimeTypeFromContentType: arg
-
initialization
-
closeKeptConnections
-
-
initialize
-
instance creation
-
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.
-
new
-
-
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
-
generateFieldDataFrom: nameValueAssociations
-
-
multiPartBoundaryPost: url filename: aFilename fileNameFieldName: aFilenameFieldName contents: contents otherValues: aValueDict
-
a post request with field values in a smalltalk-friendly form
-
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
-
get: url
-
get url; returns a response-object
-
get: url accept: acceptedMimeTypes
-
get url, accepting types in acceptedMimeTypes.
Returns a response-object.
-
get: url destinationFile: destinationFilename
-
get url; returns a response-object. Data is stored in destinationFile
-
get: url fromDocument: referrer
-
get url; returns a response-object
-
get: path fromHost: host
-
get path from host.
Returns a response-object.
-
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.
-
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.
-
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.
-
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.
-
get: url userName: user password: password
-
get url; Returns a response-object.
-
get: url with: data
-
a get request with field values in HTTP-request form (&nameKey=value;).
returns a response-object
-
get: url withFields: nameValueAssociations
-
a get request with field values.
returns a response-object
-
getFile: url
-
a get request, returning the data if present, or else raising an error.
-
multiPartBoundaryPost: url fromHost: host port: port userName: userName password: password attributes: aValueDict
-
a post request with field values in a smalltalk-friendly form
-
post: url with: data
-
a post request with field values in HTTP-request form (&nameKey=value;)
-
post: url withFields: nameValueAssociations
-
-
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.
-
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
-
validateAStringOnW3Org: aString
-
accessing
-
acceptedCharsets
-
-
acceptedCharsets: something
-
-
acceptedEncodings
-
-
acceptedEncodings: something
-
-
acceptedLanguages
-
-
acceptedLanguages: something
-
-
acceptedMimeTypes
-
-
acceptedMimeTypes: something
-
-
additionalHeaderLines
-
-
additionalHeaderLines: something
-
-
connectTimeout
-
-
connectTimeout: something
-
set the connectionTimeout in seconds
-
contentType
-
-
contentType: something
-
-
contents
-
-
contents: something
-
-
destinationFile: aFilename
-
if given, received data will be stored there, instead of being returned
as string/byteAray. use this for bug file transfers
-
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
-
password
-
-
password: something
-
-
referer
-
-
referer: something
-
-
socket
-
-
socket: aSocket
-
-
suppressUnicode: aBoolean
-
-
transferTimeout
-
-
transferTimeout: seconds
-
set the transferTimeout in seconds
-
userAgent
-
-
userAgent: something
-
-
userName
-
-
userName: something
-
helpers
-
acceptString: aStringOrCollection for: what
-
-
authenticationStringForUser: user password: passwd
-
-
close
-
-
closeSocket
-
-
decodeData: data forMimeType: mimeType andEncoding: encoding into: aResponse
-
-
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.
-
doRequest: getOrPost
-
-
extractTransferParametersFromInfo: info
-
-
getResponse
-
-
logInfo: msg
-
-
parseInfo: rawHeader into: anHTTPResponse
-
-
receiveDocument
-
-
sendData: data
-
-
socketHandlingAfterRequestWithResponse: responseArg
-
cache the connection/socket for future requests.
Weather we do caching, depends on the returned HTTP response
-
transferRateStringFor: bytesTransferedPerSecond
-
initialization
-
connectTo: hostName port: portNrOrNil
-
-
connectTo: hostName port: portNrOrNil useSSL: useSSL
-
-
initialize
-
-
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
-
dataBufferSize
-
-
isConnected
-
release
-
destroy
-
requests
-
request: getOrPost url: urlArg
-
-
requestDELETE: args url: urlArg
-
-
requestGET: urlArg
-
-
requestHEAD: urlArg
-
-
requestPOST: args url: urlArg
-
-
requestPUT: args url: urlArg
-
requests - obsolete backward compatibility
-
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) **
-
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) **
-
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) **
-
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) **
-
requestGET: url accept: acceptedMimeTypes
-
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
requestGET: url accept: acceptedMimeTypes from: currentURL
-
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
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) **
-
requestGET: urlArg from: refererString
-
** This is an obsolete interface - do not use it (it may vanish in future versions) **
HTTPResponse
KeptSocketInfo
TransferProgressNotificationSignal
TransferTimeoutNotificationSignal
|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.
]
|
|