Memoize

BasicWerk   EC Support   Technique   Facebook  

20140721101342_factor_http_head

factor_http_head

 

関連記事:

 

http://basicwerk.com/memoize/20140614111235_factor_http_download_recover.html

 

 
! 存在しない url(string)
IN: scratchpad auto-use "http://basicwerk.com/image/bw_SSxxxxx.png"
 
--- Data stack:
"http://basicwerk.com/image/bw_SSxxxxx.png"
 
! string -> url
IN: scratchpad auto-use >url
 
--- Data stack:
URL" http://basicwerk.com/image/bw_SSxxxxx.png"
 
! url -> head request
IN: scratchpad auto-use <head-request>
 
--- Data stack:
T{ request f "HEAD"...
IN: scratchpad auto-use dup .
    T{ request
        { method "HEAD" }
        { url URL" http://basicwerk.com/image/bw_SSxxxxx.png" }
        { version "1.1" }
        { header
            H{
                { "user-agent" "Factor http.client" }
                { "connection" "close" }
            }
        }
        { cookies V{ } }
        { redirects 10 }
    }
 
--- Data stack:
    T{ request f "HEAD"...
 
! recover でエラーをキャッチ
! エラーの際は response tuple が返されるので
! response から code を取り出す
IN: scratchpad auto-use [ http-request drop code>> ] [ response>> code>> nip ] recover
 
--- Data stack:
404
 

 

http://docs.factorcode.org/content/vocab-http.client.html

http://docs.factorcode.org/content/word-__lt__head-request__gt__%2Chttp.client.html

http://docs.factorcode.org/content/word-http-request,http.client.html

http://docs.factorcode.org/content/word-recover,continuations.html

 

#factorcode

 


© Shin Nakamura/BasicWerk 2014