]> gitweb.factorcode.org Git - factor.git/blob - extra/images/http/http.factor
factor: trim more using lists.
[factor.git] / extra / images / http / http.factor
1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors combinators.short-circuit http.client
4 images.loader images.loader.private images.viewer io.pathnames
5 kernel present sequences strings urls ;
6 IN: images.http
7
8 <PRIVATE
9
10 : content-type ( response -- type/f )
11     content-type>> dup "image/" head?
12     [ 6 tail ] [ drop f ] if ;
13
14 PRIVATE>
15
16 : load-http-image ( path -- image )
17     [ http-get swap content-type ]
18     [ present file-extension ] bi or
19     (image-class) load-image* ;
20
21 M: string set-image
22     dup { [ "http://" head? ] [ "https://" head? ] } 1||
23     [ load-http-image ] [ load-image ] if >>image ;
24
25 M: url set-image
26     protocol>> load-http-image >>image ;
27
28 : http-image. ( path -- )
29     load-http-image image. ;