I’m trying to migrate the Pier link checker to Pharo 3, going from
HTTPSocket to ZnClient. Looks like a good API improvement, but some things
are still different. http://humane-assessment.com claims not to  support
this head request (501), as does http:://cognitive-edge.com (404).
Anyone know what I should change? 
Stephan

httpHead: aString
        "Answer an array with response code and effective URL, or nil."

        | response |
                response := ZnClient new 
                url: aString trimBoth;
                timeout: 1;
                method: #HEAD; 
                ifFail: [ ^Array with: 404 with: aString ];
                executeWithTimeout;
                response.
        ^ Array with: response code with: (response headers at: 'Location' 
ifAbsent: [aString]) .

httpHead: aString
        "Answer an array with response code and effective URL, or nil."

        | url socket |
        url := Url absoluteFromText: aString.
        (url isKindOf: HttpUrl)
                ifFalse: [ ^ nil ].
        [ socket := HTTPSocket
                initHTTPSocket: url
                wait: (HTTPSocket deadlineSecs: 1)
                ifError: [ ^ Array with: 404 with: aString ] ]
                        on: NameLookupFailure
                        do: [ :err | ^ Array with: 404 with: aString ].
        ^ [ [ socket sendCommand: ('HEAD ' , ((HTTPSocket shouldUseProxy: url 
authority)
                ifTrue: [ url printString ] ifFalse: [ url fullPath ]) ,  ' 
HTTP/1.0' , String crlf) ,
                        ('Host: ' , url authority , String crlf) , 
                        (HTTPSocket userAgentString , String crlf) ,
                        (HTTPSocket classPool at: #HTTPProxyCredentials).
                socket header: (socket getResponseUpTo: String crlf , String 
crlf) first.
                Array with: socket responseCode asInteger with: (socket 
getHeader: 'location' default: aString) ]
                        on: Error do: [ :err | nil ] ]
                        ensure: [ socket destroy ]

Reply via email to