The Trunk: Network-topa.144.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Network-topa.144.mcz

commits-2
Tobias Pape uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-topa.144.mcz

==================== Summary ====================

Name: Network-topa.144
Author: topa
Time: 10 September 2013, 10:15:39.131 pm
UUID: b114e5c1-0198-49d2-a661-be9f838f9682
Ancestors: Network-cmm.143

Enable handling of HTTP redirects in HTTPSocket.

=============== Diff against Network-cmm.143 ===============

Item was changed:
  ----- Method: HTTPSocket class>>httpRequest:url:headers:content:response: (in category 'get the page') -----
  httpRequest: method url: urlString headers: hdrs content: contentOrNil response: responseBlock
 
  "Sends an HTTP request to the server. Returns a MIMEDocument if successful,
  a string indicating the error otherwise. If a response block is provided, the
  response is fed into into so that the sender can see all the headers.
  The url string is assumed to be properly escaped by the sender."
 
  | index serverAndPort server port rawUrl stream resp code headers
   contentLength contentType contentStream |
 
  (urlString beginsWith: 'http://') ifFalse:[self error: 'Not a http url'].
 
  "Extract server, port, and url"
  index := urlString indexOf: $/ startingAt: 8 ifAbsent:[urlString size+1]. "past http://"
  serverAndPort := urlString copyFrom: 8 to: index-1.
  server := serverAndPort copyUpTo: $:.
  port := ((serverAndPort copyAfter: $:) ifEmpty:['80']) asNumber.
 
  "Prepare the request URI"
  rawUrl := urlString copyFrom: index to: urlString size.
  (rawUrl beginsWith: '/') ifFalse:[rawUrl := '/', rawUrl].
 
  "Check for proxy"
  (self shouldUseProxy: server) ifTrue:[
  self httpProxyServer ifNotEmpty:[
  rawUrl := 'http://', serverAndPort, rawUrl. "per RFC 2616"
  server := self httpProxyServer.
  port := self httpProxyPort.
  ].
  ].
 
  "Fire off the request"
  stream := SocketStream openConnectionToHostNamed: server port: port.
  stream nextPutAll: method; space; nextPutAll: rawUrl; space; nextPutAll: 'HTTP/1.0'; crlf.
  stream nextPutAll: 'Host: ', serverAndPort; crlf.
  stream nextPutAll: 'Connection: close'; crlf.
  stream nextPutAll: 'User-Agent: ', self userAgentString; crlf.
  stream nextPutAll: hdrs.
  stream crlf.
 
  contentOrNil ifNotNil:[
  "Upload request content"
  contentStream := contentOrNil readStream.
  [contentStream atEnd] whileFalse:[
  (HTTPProgress new) total: contentOrNil size;
  amount: contentStream position; signal: 'Uploading...'.
  stream nextPutAll: (contentStream next: 4096).
  stream flush.
  ].
  ].
 
  stream flush.
 
  "Read the response"
  resp := stream upToAll: String crlfcrlf.
  "Extract the response code"
  code := ((resp copyUpTo: String cr) findTokens: ' ') second asNumber.
  "And the response headers"
  headers := Dictionary new.
  resp lines allButFirst allButLast do:[:nextLine|
  headers at: (nextLine copyUpTo: $:) asLowercase
  put: (nextLine copyAfter: $:) withBlanksTrimmed.
  ].
 
+       (code between: 301 and: 303)
+ ifTrue:[
+ headers at: 'location' ifPresent: [:location |
+ stream close.
+ ^ self httpRequest: method url: location headers: hdrs content: contentOrNil response: responseBlock]].
+
+
  "Read response content"
  contentLength := headers at: 'content-length' ifAbsent:[nil].
  contentType := headers at: 'content-type' ifAbsent:['application/octet-stream'].
  "Fixme - Provide HTTProgress"
  contentLength
  ifNil:[contentStream := WriteStream with: stream upToEnd]
  ifNotNil:[
  contentLength := contentLength asNumber.
  contentStream := (String new: contentLength) writeStream.
  [contentStream position < contentLength] whileTrue:[
  contentStream nextPutAll:
  (stream next: (contentLength - contentStream position min: 4096)).
  (HTTPProgress new) total: contentLength;
  amount: contentStream position; signal: 'Downloading...'.
  ].
  ].
  stream close.
 
  responseBlock ifNotNil:[responseBlock value: resp].
 
  ^(code between: 200 and: 299)
  ifTrue:[MIMEDocument contentType: contentType
  content: contentStream contents url: urlString]
  ifFalse:[resp asString, contentStream contents].
  !


Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Network-topa.144.mcz

Tobias Pape
This fixes the issues with HTTP redirects
in Monticello, among others.

If nobody objects until tomorrow morning, I will apply
this to squeak 4.2, 4.3, and 4.4.

Best
        -Tobias

Am 10.09.2013 um 20:15 schrieb [hidden email]:

> Tobias Pape uploaded a new version of Network to project The Trunk:
> http://source.squeak.org/trunk/Network-topa.144.mcz
>
> ==================== Summary ====================
>
> Name: Network-topa.144
> Author: topa
> Time: 10 September 2013, 10:15:39.131 pm
> UUID: b114e5c1-0198-49d2-a661-be9f838f9682
> Ancestors: Network-cmm.143
>
> Enable handling of HTTP redirects in HTTPSocket.
>
> =============== Diff against Network-cmm.143 ===============
>
> Item was changed:





signature.asc (210 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Network-topa.144.mcz

Frank Shearar-3
The change looks good. This is me loudly not objecting :)

frank

On 10 September 2013 21:27, Tobias Pape <[hidden email]> wrote:

> This fixes the issues with HTTP redirects
> in Monticello, among others.
>
> If nobody objects until tomorrow morning, I will apply
> this to squeak 4.2, 4.3, and 4.4.
>
> Best
>         -Tobias
>
> Am 10.09.2013 um 20:15 schrieb [hidden email]:
>
>> Tobias Pape uploaded a new version of Network to project The Trunk:
>> http://source.squeak.org/trunk/Network-topa.144.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Network-topa.144
>> Author: topa
>> Time: 10 September 2013, 10:15:39.131 pm
>> UUID: b114e5c1-0198-49d2-a661-be9f838f9682
>> Ancestors: Network-cmm.143
>>
>> Enable handling of HTTP redirects in HTTPSocket.
>>
>> =============== Diff against Network-cmm.143 ===============
>>
>> Item was changed:
>
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Network-topa.144.mcz

Tobias Pape
Am 11.09.2013 um 08:35 schrieb Frank Shearar <[hidden email]>:

> The change looks good. This is me loudly not objecting :)
>

Change deployed to
        4.2 Network-topa.106
        4.3 Network-topa.123
        4.4 Network-topa.139

Somebody who has write-access to ftp.squeak.org should
put updated images / zip-packages for those versions
there :)

Best
        -Tobias