'From Squeakland 3.1.3905 [latest update: #14] on 29 April 2001 at 12:28:12 am'! "Change Set: httpFixes Date: 29 April 2001 Author: Michael Rueger Adds http-get methods to HTTPClient and changes the update mechanism to make use of it. Puts in a workaround for the http-post problems with IE on Macs."! !HTTPClient class methodsFor: 'utilities' stamp: 'mir 4/28/2001 23:46'! getDirectoryListing: dirListURL | answer ftpEntries | " answer _ self httpPostDocument: dirListURL args: Dictionary new." "Workaround for Mac IE problem" answer _ self httpGetDocument: dirListURL. answer isString ifTrue: [^self error: 'Listing failed: ' , answer] ifFalse: [answer _ answer content]. answer first == $< ifTrue: [self error: 'Listing failed: ' , answer]. ftpEntries _ answer findTokens: SimpleClientSocket crLf. ^ ftpEntries collect:[:ftpEntry | ServerDirectory parseFTPEntry: ftpEntry] thenSelect: [:entry | entry notNil]! ! !HTTPClient class methodsFor: 'post/get' stamp: 'mir 4/28/2001 23:36'! httpGet: url | document | document _ self httpGetDocument: url. ^(document isKindOf: String) ifTrue: [ "strings indicate errors" document] ifFalse: [(RWBinaryOrTextStream with: document content) reset]! ! !HTTPClient class methodsFor: 'post/get' stamp: 'mir 4/28/2001 23:35'! httpGetDocument: url | stream content | ^self shouldUsePluginAPI ifTrue: [ stream _ FileStream requestURLStream: url ifError: [self error: 'Error in get from ' , url printString]. stream ifNil: [^'']. stream position: 0. content _ stream upToEnd. stream close. MIMEDocument content: content] ifFalse: [HTTPSocket httpGetDocument: url]! ! !Utilities class methodsFor: 'fetching updates' stamp: 'mir 5/22/2001 18:54'! newUpdatesOn: serverList special: indexPrefix throughNumber: aNumber "Return a list of fully formed URLs of update files we do not yet have. Go to the listed servers and look at the file 'updates.list' for the names of the last N update files. We look backwards for the first one we have, and make the list from there. tk 9/10/97 No updates numbered higher than aNumber (if it is not nil) are returned " | existing doc list out ff raw char maxNumber itsNumber | maxNumber _ aNumber ifNil: [99999]. out _ OrderedCollection new. existing _ SystemVersion current updates. serverList do: [:server | doc _ HTTPClient httpGet: 'http://' , server,indexPrefix,'updates.list'. "test here for server being up" doc class == RWBinaryOrTextStream ifTrue: [raw _ doc reset; contents. "one file name per line" list _ self extractThisVersion: raw. list reverseDo: [:fileName | ff _ (fileName findTokens: '/') last. "allow subdirectories" itsNumber _ ff initialIntegerOrNil. (existing includes: itsNumber) ifFalse: [ (itsNumber == nil or: [itsNumber <= maxNumber]) ifTrue: [out addFirst: server, fileName]] ifTrue: [^ out]]. ((out size > 0) or: [char _ doc reset; skipSeparators; next. (char == $*) | (char == $#)]) ifTrue: [^ out "we have our list"]]. "else got error msg instead of file" "Server was down, try next one"]. PopUpMenu notify: 'All code update servers seem to be unavailable'. ^ out! ! !Utilities class methodsFor: 'fetching updates' stamp: 'mir 4/28/2001 23:59'! retrieveUrls: urls ontoQueue: queue withWaitSema: waitSema "download the given list of URLs. The queue will be loaded alternately with url's and with the retrieved contents. If a download fails, the contents will be #failed. If all goes well, a special pair with an empty URL and the contents #finished will be put on the queue. waitSema is waited on every time before a new document is downloaded; this keeps the downloader from getting too far ahead of the main process" "kill the existing downloader if there is one" | doc canPeek front | UpdateDownloader ifNotNil: [UpdateDownloader terminate]. "fork a new downloading process" UpdateDownloader _ [urls do: [:url | waitSema wait. queue nextPut: url. doc _ HTTPClient httpGet: url. doc class == String ifTrue: [queue nextPut: #failed. UpdateDownloader _ nil. Processor activeProcess terminate] ifFalse: [canPeek _ 120 min: doc size. front _ doc next: canPeek. doc skip: -1 * canPeek. (front beginsWith: '