[squeak-dev] The Trunk: Network-ar.45.mcz
commits at source.squeak.org
commits at source.squeak.org
Tue Dec 29 14:00:02 UTC 2009
Andreas Raab uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-ar.45.mcz
==================== Summary ====================
Name: Network-ar.45
Author: ar
Time: 29 December 2009, 2:59:19 am
UUID: 862cde17-6162-084b-bfc0-7a17bfe2c660
Ancestors: Network-nice.44, Network-tonyg.35
Merging Network-tonyg.35:
Do not specify ':80' (or other port number) in HTTP request 'Host' header unless a port number was explicitly specified, because doing so changes the meaning of the request when HTTP virtual-hosts are being used.
=============== Diff against Network-nice.44 ===============
Item was changed:
+ ----- Method: HTTPSocket class>>httpGetDocument:args:accept:request: (in category 'get the page') -----
- ----- Method: HTTPSocket class>>httpGetDocument:args:accept:request: (in category 'proxy settings') -----
httpGetDocument: url args: args accept: mimeType request: requestString
"Return the exact contents of a web object. Asks for the given MIME
type. If mimeType is nil, use 'text/html'. An extra requestString may be
submitted and must end with crlf. The parsed header is saved. Use a
proxy server if one has been registered. tk 7/23/97 17:12"
"Note: To fetch raw data, you can use the MIME type
'application/octet-stream'."
+ | serverName serverAddr port bare page index connectToHost connectToPort aStream portSuffix |
- | serverName serverAddr port bare page index connectToHost connectToPort aStream |
Socket initializeNetwork.
bare := (url asLowercase beginsWith: 'http://')
ifTrue: [url copyFrom: 8 to: url size]
ifFalse: [url].
bare := bare copyUpTo: $#. "remove fragment, if specified"
serverName := bare copyUpTo: $/.
page := bare copyFrom: serverName size + 1 to: bare size.
(serverName includes: $:)
ifTrue: [ index := serverName indexOf: $:.
port := (serverName copyFrom: index+1 to: serverName size) asNumber.
+ portSuffix := ':', port printString.
serverName := serverName copyFrom: 1 to: index-1. ]
+ ifFalse: [
+ port := self defaultPort.
+ portSuffix := ''. ].
- ifFalse: [ port := self defaultPort ].
page size = 0 ifTrue: [page := '/'].
"add arguments"
args ifNotNil: [page := page, (self argString: args) ].
(self shouldUseProxy: serverName)
ifFalse: [
connectToHost := serverName.
connectToPort := port ]
ifTrue: [
+ page := 'http://', serverName, portSuffix, page. "put back
- page := 'http://', serverName, ':', port printString, page. "put back
together"
connectToHost := self httpProxyServer.
connectToPort := self httpProxyPort].
serverAddr := NetNameResolver addressForName: connectToHost timeout: 20.
serverAddr ifNil: [
^ 'Could not resolve the server named: ', connectToHost].
3 timesRepeat: [ | sock length firstData list type header newUrl |
sock := HTTPSocket new.
sock connectTo: serverAddr port: connectToPort.
(sock waitForConnectionUntil: (self deadlineSecs: 30)) ifFalse: [
Socket deadServer: connectToHost. sock destroy.
^ 'Server ',connectToHost,' is not responding'].
"Transcript cr;show: url; cr.
Transcript show: page; cr."
sock sendCommand: 'GET ', page, ' HTTP/1.0', CrLf,
(mimeType ifNotNil: ['ACCEPT: ', mimeType, CrLf] ifNil: ['']),
'ACCEPT: text/html', CrLf, "Always accept plain text"
HTTPBlabEmail, "may be empty"
requestString, "extra user request. Authorization"
self userAgentString, CrLf,
+ 'Host: ', serverName, portSuffix, CrLf. "blank line
- 'Host: ', serverName, ':', port printString, CrLf. "blank line
automatically added"
+ list := sock getResponseUpTo: CrLf, CrLf ignoring: (String with: CR). "list = header, CrLf, CrLf,
- list := sock getResponseUpTo: CrLf, CrLf ignoring: String cr. "list = header, CrLf, CrLf,
beginningOfData"
header := list at: 1.
"Transcript show: page; cr; show: header; cr."
firstData := list at: 3.
header isEmpty
ifTrue: [aStream := 'server aborted early']
ifFalse: [
"dig out some headers"
sock header: header.
length := sock getHeader: 'content-length'.
length ifNotNil: [ length := length asNumber ].
type := sock getHeader: 'content-type'.
sock responseCode first = $3 ifTrue: [
newUrl := sock getHeader: 'location'.
newUrl ifNotNil: [
Transcript show: 'redirecting to ', newUrl; cr.
sock destroy.
newUrl := self expandUrl: newUrl ip: serverAddr port: connectToPort.
^self httpGetDocument: newUrl args: args accept: mimeType request: requestString] ].
aStream := sock getRestOfBuffer: firstData totalLength: length.
"a 400-series error"
sock responseCode first = $4 ifTrue: [^ header, aStream contents].
].
sock destroy. "Always OK to destroy!!"
aStream class ~~ String ifTrue: [
^ MIMEDocument contentType: type content: aStream contents url: url].
aStream = 'server aborted early' ifTrue: [ ^aStream ].
].
{'HTTPSocket class>>httpGetDocument:args:accept:request:'. aStream. url} inspect.
^'some other bad thing happened!!'!
More information about the Squeak-dev
mailing list
|