http: clean up and fix some content encoding logic
parent
cb0e99a962
commit
937b05f1de
|
@ -7,7 +7,7 @@ io io.sockets io.streams.string io.files io.timeouts
|
|||
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 ;
|
||||
|
@ -51,13 +51,18 @@ 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 )
|
||||
|
|
|
@ -5,7 +5,7 @@ sequences splitting sorting sets strings vectors hashtables
|
|||
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
|
||||
|
@ -223,4 +223,4 @@ TUPLE: post-data data params content-type content-encoding ;
|
|||
: 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* ;
|
||||
|
|
|
@ -26,6 +26,7 @@ http.server.remapping
|
|||
html.templates
|
||||
html.streams
|
||||
html
|
||||
mime.types
|
||||
xml.writer ;
|
||||
FROM: mime.multipart => parse-multipart ;
|
||||
IN: http.server
|
||||
|
@ -102,7 +103,7 @@ GENERIC: write-full-response ( request response -- )
|
|||
|
||||
: 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* ;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
! 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
|
||||
|
||||
|
@ -23,3 +24,7 @@ MEMO: mime-types ( -- assoc )
|
|||
|
||||
: mime-type ( filename -- mime-type )
|
||||
file-extension mime-types at "application/octet-stream" or ;
|
||||
|
||||
: mime-type-encoding ( mime-type -- encoding )
|
||||
"text/" head? utf8 binary ? ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue