]> gitweb.factorcode.org Git - factor.git/commitdiff
images.http: use the content type from the http response if provided.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 27 Jan 2011 02:05:02 +0000 (18:05 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 27 Jan 2011 02:05:02 +0000 (18:05 -0800)
basis/images/loader/loader.factor
extra/images/http/http.factor

index 7e1dc9ca3186f2fc1bd20aae5d7dec55ec052a9a..52a80459d9d1b5416f06275c97dd9febd498b787 100644 (file)
@@ -13,9 +13,11 @@ ERROR: unknown-image-extension extension ;
 SYMBOL: types
 types [ H{ } clone ] initialize
 
+: (image-class) ( type -- class )
+    >lower types get ?at [ unknown-image-extension ] unless ;
+
 : image-class ( path -- class )
-    file-extension >lower types get ?at
-    [ unknown-image-extension ] unless ;
+    file-extension (image-class) ;
 
 : open-image-file ( path -- stream )
     binary <limited-file-reader> ;
index 620ab6f73b956df5affdb19e5f67db2290219ea9..217c8408d1028ff2f2e7aec035c42e80d111abdb 100644 (file)
@@ -1,11 +1,21 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: http.client images.loader images.loader.private kernel
-images.viewer ;
+USING: accessors assocs http.client images.loader
+images.loader.private images.viewer io.pathnames kernel
+namespaces sequences ;
 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 )
-    [ http-get nip ] [ image-class ] bi load-image* ;
+    [ http-get swap content-type ] [ file-extension ] bi or
+    (image-class) load-image* ;
 
 : http-image. ( path -- )
     load-http-image image. ;