The Trunk: WebClient-Core-topa.109.mcz

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

The Trunk: WebClient-Core-topa.109.mcz

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

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

Name: WebClient-Core-topa.109
Author: topa
Time: 6 July 2017, 3:27:22.152308 pm
UUID: b795898b-9723-44ab-a429-bceb056f4b90
Ancestors: WebClient-Core-topa.108

As with content-type-charset, cope for content-encoding variability

=============== Diff against WebClient-Core-topa.108 ===============

Item was added:
+ ----- Method: WebClient>>contentDecoders (in category 'initialize') -----
+ contentDecoders
+
+ | result |
+ result := nil.
+ (self class environment hasBindingOf: #GZipReadStream)
+ ifTrue: [result := 'gzip'].
+ (self class environment hasBindingOf: #BrotliReadStream)
+ ifTrue: [ result := result ifNil: ['br'] ifNotNil: [:r | r, ', br']].
+ ^ result!

Item was changed:
  ----- Method: WebClient>>httpGet:do: (in category 'methods') -----
  httpGet: urlString do: aBlock
  "GET the response from the given url"
  "(WebClient httpGet: 'http://www.squeak.org') content"
 
  | request |
  self initializeFromUrl: urlString.
  request := self requestWithUrl: urlString.
  request method: 'GET'.
+ userAgent ifNotNil:[:ua | request headerAt: 'User-Agent' put: ua].
+ self contentDecoders ifNotNil: [:decoders | request headerAt: 'Accept-Encoding' put: decoders].
- userAgent ifNotNil:[request headerAt: 'User-Agent' put: userAgent].
- request headerAt: 'Accept-Encoding' put: 'gzip'.
  aBlock value: request.
  ^self sendRequest: request
  !

Item was added:
+ ----- Method: WebMessage>>decoderForContentEncoding (in category 'private') -----
+ decoderForContentEncoding
+
+ (self headerAt: 'content-encoding') = 'gzip'
+ ifTrue: [^ self class environment
+ at: #GZipReadStream ifAbsent: [self error: 'GZip encoded responses not supported']].
+ (self headerAt: 'content-encoding') = 'br'
+ ifTrue: [^ self class environment
+ at: #BrotliReadStream ifAbsent: [self error: 'Brotli encoded responses not supported']].
+ ^ nil!

Item was changed:
  ----- Method: WebMessage>>getContentWithProgress: (in category 'private') -----
  getContentWithProgress: progressBlockOrNil
  "Reads available content and returns it."
 
  | length result |
  length := self contentLength.
  result := (stream isBinary ifTrue:[ ByteArray ] ifFalse: [ ByteString ])
  new: (length ifNil: [ 1000 ])
  streamContents: [ :outputStream |
  self
  streamFrom: stream
  to: outputStream
  size: length
  progress: progressBlockOrNil ].
+ self decoderForContentEncoding ifNotNil: [:decoder |
+ result := (decoder on: result) upToEnd].
- (self headerAt: 'content-encoding') = 'gzip' ifTrue: [
- result :=  (GZipReadStream on: result) upToEnd].
  self textConverterForContentType ifNotNil: [:converter |
  result := result convertFromWithConverter: converter].
  ^ result
  !


Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: WebClient-Core-topa.109.mcz

Levente Uzonyi
Where does BrotliReadStream come from?

Also, #hasBindingOf: seems dangerous to use as it uses declarations
instead of bindings or both to look up the binding, while other
binding-related methods use bindings (e.g. #bindingOf:ifAbsent:,
#hasBindingThatBeginsWith:, #hideBinding:, #associationOrUndeclaredAt:).
It will probably work as long as there's only a single environment.

Levente

On Thu, 6 Jul 2017, [hidden email] wrote:

> Tobias Pape uploaded a new version of WebClient-Core to project The Trunk:
> http://source.squeak.org/trunk/WebClient-Core-topa.109.mcz
>
> ==================== Summary ====================
>
> Name: WebClient-Core-topa.109
> Author: topa
> Time: 6 July 2017, 3:27:22.152308 pm
> UUID: b795898b-9723-44ab-a429-bceb056f4b90
> Ancestors: WebClient-Core-topa.108
>
> As with content-type-charset, cope for content-encoding variability
>
> =============== Diff against WebClient-Core-topa.108 ===============
>
> Item was added:
> + ----- Method: WebClient>>contentDecoders (in category 'initialize') -----
> + contentDecoders
> +
> + | result |
> + result := nil.
> + (self class environment hasBindingOf: #GZipReadStream)
> + ifTrue: [result := 'gzip'].
> + (self class environment hasBindingOf: #BrotliReadStream)
> + ifTrue: [ result := result ifNil: ['br'] ifNotNil: [:r | r, ', br']].
> + ^ result!
>
> Item was changed:
>  ----- Method: WebClient>>httpGet:do: (in category 'methods') -----
>  httpGet: urlString do: aBlock
>   "GET the response from the given url"
>   "(WebClient httpGet: 'http://www.squeak.org') content"
>
>   | request |
>   self initializeFromUrl: urlString.
>   request := self requestWithUrl: urlString.
>   request method: 'GET'.
> + userAgent ifNotNil:[:ua | request headerAt: 'User-Agent' put: ua].
> + self contentDecoders ifNotNil: [:decoders | request headerAt: 'Accept-Encoding' put: decoders].
> - userAgent ifNotNil:[request headerAt: 'User-Agent' put: userAgent].
> - request headerAt: 'Accept-Encoding' put: 'gzip'.
>   aBlock value: request.
>   ^self sendRequest: request
>  !
>
> Item was added:
> + ----- Method: WebMessage>>decoderForContentEncoding (in category 'private') -----
> + decoderForContentEncoding
> +
> + (self headerAt: 'content-encoding') = 'gzip'
> + ifTrue: [^ self class environment
> + at: #GZipReadStream ifAbsent: [self error: 'GZip encoded responses not supported']].
> + (self headerAt: 'content-encoding') = 'br'
> + ifTrue: [^ self class environment
> + at: #BrotliReadStream ifAbsent: [self error: 'Brotli encoded responses not supported']].
> + ^ nil!
>
> Item was changed:
>  ----- Method: WebMessage>>getContentWithProgress: (in category 'private') -----
>  getContentWithProgress: progressBlockOrNil
>   "Reads available content and returns it."
>
>   | length result |
>   length := self contentLength.
>   result := (stream isBinary ifTrue:[ ByteArray ] ifFalse: [ ByteString ])
>   new: (length ifNil: [ 1000 ])
>   streamContents: [ :outputStream |
>   self
>   streamFrom: stream
>   to: outputStream
>   size: length
>   progress: progressBlockOrNil ].
> + self decoderForContentEncoding ifNotNil: [:decoder |
> + result := (decoder on: result) upToEnd].
> - (self headerAt: 'content-encoding') = 'gzip' ifTrue: [
> - result :=  (GZipReadStream on: result) upToEnd].
>   self textConverterForContentType ifNotNil: [:converter |
>   result := result convertFromWithConverter: converter].
>   ^ result
>  !

Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: WebClient-Core-topa.109.mcz

Tobias Pape
Hi,

> On 08.07.2017, at 15:15, Levente Uzonyi <[hidden email]> wrote:
>
> Where does BrotliReadStream come from?

My imagination and wishful thinking, to be frank…
A reminder for me, that I actually want to implement that…

>
> Also, #hasBindingOf: seems dangerous to use as it uses declarations instead of bindings or both to look up the binding, while other binding-related methods use bindings (e.g. #bindingOf:ifAbsent:, #hasBindingThatBeginsWith:, #hideBinding:, #associationOrUndeclaredAt:).
> It will probably work as long as there's only a single environment.

Eeek. I used hasClassNamed: there, but that also just seemed to use the declarations.
I understand that I don't understand enough of Environments yet.

Best regards
        -Tobias




>
> Levente
>
> On Thu, 6 Jul 2017, [hidden email] wrote:
>
>> Tobias Pape uploaded a new version of WebClient-Core to project The Trunk:
>> http://source.squeak.org/trunk/WebClient-Core-topa.109.mcz
>>
>> ==================== Summary ====================
>>
>> Name: WebClient-Core-topa.109
>> Author: topa
>> Time: 6 July 2017, 3:27:22.152308 pm
>> UUID: b795898b-9723-44ab-a429-bceb056f4b90
>> Ancestors: WebClient-Core-topa.108
>>
>> As with content-type-charset, cope for content-encoding variability
>>
>> =============== Diff against WebClient-Core-topa.108 ===============
>>
>> Item was added:
>> + ----- Method: WebClient>>contentDecoders (in category 'initialize') -----
>> + contentDecoders
>> + + | result |
>> + result := nil.
>> + (self class environment hasBindingOf: #GZipReadStream)
>> + ifTrue: [result := 'gzip'].
>> + (self class environment hasBindingOf: #BrotliReadStream)
>> + ifTrue: [ result := result ifNil: ['br'] ifNotNil: [:r | r, ', br']].
>> + ^ result!
>>
>> Item was changed:
>> ----- Method: WebClient>>httpGet:do: (in category 'methods') -----
>> httpGet: urlString do: aBlock
>> "GET the response from the given url"
>> "(WebClient httpGet: 'http://www.squeak.org') content"
>>
>> | request |
>> self initializeFromUrl: urlString.
>> request := self requestWithUrl: urlString.
>> request method: 'GET'.
>> + userAgent ifNotNil:[:ua | request headerAt: 'User-Agent' put: ua].
>> + self contentDecoders ifNotNil: [:decoders | request headerAt: 'Accept-Encoding' put: decoders].
>> - userAgent ifNotNil:[request headerAt: 'User-Agent' put: userAgent].
>> - request headerAt: 'Accept-Encoding' put: 'gzip'.
>> aBlock value: request.
>> ^self sendRequest: request
>> !
>>
>> Item was added:
>> + ----- Method: WebMessage>>decoderForContentEncoding (in category 'private') -----
>> + decoderForContentEncoding
>> + + (self headerAt: 'content-encoding') = 'gzip'
>> + ifTrue: [^ self class environment
>> + at: #GZipReadStream ifAbsent: [self error: 'GZip encoded responses not supported']].
>> + (self headerAt: 'content-encoding') = 'br'
>> + ifTrue: [^ self class environment
>> + at: #BrotliReadStream ifAbsent: [self error: 'Brotli encoded responses not supported']].
>> + ^ nil!
>>
>> Item was changed:
>> ----- Method: WebMessage>>getContentWithProgress: (in category 'private') -----
>> getContentWithProgress: progressBlockOrNil
>> "Reads available content and returns it."
>>
>> | length result |
>> length := self contentLength.
>> result := (stream isBinary ifTrue:[ ByteArray ] ifFalse: [ ByteString ])
>> new: (length ifNil: [ 1000 ])
>> streamContents: [ :outputStream |
>> self
>> streamFrom: stream
>> to: outputStream
>> size: length
>> progress: progressBlockOrNil ].
>> + self decoderForContentEncoding ifNotNil: [:decoder |
>> + result := (decoder on: result) upToEnd].
>> - (self headerAt: 'content-encoding') = 'gzip' ifTrue: [
>> - result :=  (GZipReadStream on: result) upToEnd].
>> self textConverterForContentType ifNotNil: [:converter |
>> result := result convertFromWithConverter: converter].
>> ^ result
>> !
>