io.pathnames io.encodings io.encodings.string io.encodings.ascii
io.encodings.utf8 io.encodings.binary io.encodings.iana io.crlf
io.streams.duplex fry ascii urls urls.encoding present locals
-http http.parsers http.client.post-data ;
+http http.parsers http.client.post-data mime.types ;
IN: http.client
ERROR: too-many-redirects ;
read-crlf parse-response-line first3
[ >>version ] [ >>code ] [ >>message ] tri* ;
+: detect-encoding ( response -- encoding )
+ [ content-charset>> name>encoding ]
+ [ content-type>> mime-type-encoding ] bi
+ or ;
+
: read-response-header ( response -- response )
read-header >>header
dup "set-cookie" header parse-set-cookie >>cookies
dup "content-type" header [
parse-content-type
[ >>content-type ] [ >>content-charset ] bi*
- dup content-charset>> name>encoding >>content-encoding
+ dup detect-encoding >>content-encoding
] when* ;
: read-response ( -- response )
quotations arrays byte-arrays math.parser calendar
calendar.format present urls fry io io.encodings
io.encodings.iana io.encodings.binary io.encodings.utf8 io.crlf
-ascii io.encodings.8-bit.latin1 http.parsers base64 ;
+ascii io.encodings.8-bit.latin1 http.parsers base64 mime.types ;
IN: http
CONSTANT: max-redirects 10
: parse-content-type ( content-type -- type encoding )
";" split1
parse-content-type-attributes "charset" swap at
- [ dup "text/" head? "UTF-8" and ] unless* ;
+ [ dup mime-type-encoding encoding>name ] unless* ;
html.templates
html.streams
html
+mime.types
xml.writer ;
FROM: mime.multipart => parse-multipart ;
IN: http.server
: unparse-content-type ( request -- content-type )
[ content-type>> ] [ content-charset>> ] bi
- over "text/" head? [ "UTF-8" or ] when
+ over mime-type-encoding encoding>name or
[ "application/octet-stream" or ] dip
[ "; charset=" glue ] when* ;
-! Copyright (C) 2004, 2008 Slava Pestov.
+! Copyright (C) 2004, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: io.pathnames io.files io.encodings.ascii assocs sequences
+USING: io.pathnames io.files io.encodings.ascii
+io.encodings.binary io.encodings.utf8 assocs sequences
splitting kernel namespaces fry memoize ;
IN: mime.types
: mime-type ( filename -- mime-type )
file-extension mime-types at "application/octet-stream" or ;
+
+: mime-type-encoding ( mime-type -- encoding )
+ "text/" head? utf8 binary ? ;
+