images.http: use the content type from the http response if provided.
parent
1037a30e4d
commit
1defecf279
|
@ -13,9 +13,11 @@ ERROR: unknown-image-extension extension ;
|
||||||
SYMBOL: types
|
SYMBOL: types
|
||||||
types [ H{ } clone ] initialize
|
types [ H{ } clone ] initialize
|
||||||
|
|
||||||
|
: (image-class) ( type -- class )
|
||||||
|
>lower types get ?at [ unknown-image-extension ] unless ;
|
||||||
|
|
||||||
: image-class ( path -- class )
|
: image-class ( path -- class )
|
||||||
file-extension >lower types get ?at
|
file-extension (image-class) ;
|
||||||
[ unknown-image-extension ] unless ;
|
|
||||||
|
|
||||||
: open-image-file ( path -- stream )
|
: open-image-file ( path -- stream )
|
||||||
binary <limited-file-reader> ;
|
binary <limited-file-reader> ;
|
||||||
|
|
|
@ -1,11 +1,21 @@
|
||||||
! Copyright (C) 2009 Doug Coleman.
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: http.client images.loader images.loader.private kernel
|
USING: accessors assocs http.client images.loader
|
||||||
images.viewer ;
|
images.loader.private images.viewer io.pathnames kernel
|
||||||
|
namespaces sequences ;
|
||||||
IN: images.http
|
IN: images.http
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: content-type ( response -- type/f )
|
||||||
|
content-type>> dup "image/" head?
|
||||||
|
[ 6 tail ] [ drop f ] if ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
: load-http-image ( path -- image )
|
: load-http-image ( path -- image )
|
||||||
[ http-get nip ] [ image-class ] bi load-image* ;
|
[ http-get swap content-type ] [ file-extension ] bi or
|
||||||
|
(image-class) load-image* ;
|
||||||
|
|
||||||
: http-image. ( path -- )
|
: http-image. ( path -- )
|
||||||
load-http-image image. ;
|
load-http-image image. ;
|
||||||
|
|
Loading…
Reference in New Issue