From f8e2ddd53f162c76a21379c5307de278dc71b04c Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 13 Mar 2010 11:32:34 +1300 Subject: [PATCH 1/3] prettyprint.config: short. should not print structs as pointers --- basis/prettyprint/config/config.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/prettyprint/config/config.factor b/basis/prettyprint/config/config.factor index a8848f9061..0b2c4b888b 100644 --- a/basis/prettyprint/config/config.factor +++ b/basis/prettyprint/config/config.factor @@ -28,7 +28,7 @@ string-limit? on 2 nesting-limit set string-limit? on boa-tuples? on - c-object-pointers? on + c-object-pointers? off call ] with-scope ; inline From 02a4082e1feb23879ce821d5774acd2c757182a7 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 13 Mar 2010 19:06:41 +1300 Subject: [PATCH 2/3] http.server: decouple charset header from encoding used to send the data, and serve text files as UTF-8 by default --- basis/furnace/syndication/syndication.factor | 4 +++- basis/http/client/client.factor | 10 +++++----- basis/http/http-tests.factor | 11 ++++++----- basis/http/http.factor | 15 ++++++++------- basis/http/server/responses/responses.factor | 4 ++-- basis/http/server/server-tests.factor | 18 ++++++++++++++---- basis/http/server/server.factor | 10 ++++++---- basis/http/server/static/static.factor | 13 +++++-------- 8 files changed, 49 insertions(+), 36 deletions(-) diff --git a/basis/furnace/syndication/syndication.factor b/basis/furnace/syndication/syndication.factor index 876aaf8c98..d5d6c1cec8 100644 --- a/basis/furnace/syndication/syndication.factor +++ b/basis/furnace/syndication/syndication.factor @@ -35,7 +35,9 @@ M: object >entry ] map ; : ( body -- response ) - feed>xml "application/atom+xml" ; + feed>xml "application/atom+xml" + "UTF-8" >>content-charset + utf8 >>content-encoding ; TUPLE: feed-action < action title url entries ; diff --git a/basis/http/client/client.factor b/basis/http/client/client.factor index 482a23aeaa..d69b1ed1f3 100644 --- a/basis/http/client/client.factor +++ b/basis/http/client/client.factor @@ -1,11 +1,11 @@ -! Copyright (C) 2005, 2009 Slava Pestov. +! Copyright (C) 2005, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: assocs kernel math math.parser namespaces make sequences strings splitting calendar continuations accessors vectors math.order hashtables byte-arrays destructors 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.crlf +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 ; IN: http.client @@ -56,8 +56,8 @@ ERROR: too-many-redirects ; dup "set-cookie" header parse-set-cookie >>cookies dup "content-type" header [ parse-content-type - [ >>content-type ] - [ >>content-charset ] bi* + [ >>content-type ] [ >>content-charset ] bi* + dup content-charset>> name>encoding >>content-encoding ] when* ; : read-response ( -- response ) @@ -149,7 +149,7 @@ ERROR: download-failed response ; : http-request ( request -- response data ) [ [ % ] with-http-request ] B{ } make - over content-charset>> decode check-response-with-body ; + over content-encoding>> decode check-response-with-body ; : ( url -- request ) "GET" ; diff --git a/basis/http/http-tests.factor b/basis/http/http-tests.factor index 35d01c1014..0c396ff4e9 100644 --- a/basis/http/http-tests.factor +++ b/basis/http/http-tests.factor @@ -6,13 +6,13 @@ continuations urls hashtables accessors namespaces xml.data io.encodings.8-bit.latin1 ; IN: http.tests -[ "text/plain" latin1 ] [ "text/plain" parse-content-type ] unit-test +[ "text/plain" "UTF-8" ] [ "text/plain" parse-content-type ] unit-test -[ "text/html" utf8 ] [ "text/html; charset=UTF-8" parse-content-type ] unit-test +[ "text/html" "ASCII" ] [ "text/html; charset=ASCII" parse-content-type ] unit-test -[ "text/html" utf8 ] [ "text/html; charset=\"utf-8\"" parse-content-type ] unit-test +[ "text/html" "utf-8" ] [ "text/html; charset=\"utf-8\"" parse-content-type ] unit-test -[ "application/octet-stream" binary ] [ "application/octet-stream" parse-content-type ] unit-test +[ "application/octet-stream" f ] [ "application/octet-stream" parse-content-type ] unit-test : lf>crlf ( string -- string' ) "\n" split "\r\n" join ; @@ -115,7 +115,8 @@ blah { header H{ { "content-type" "text/html; charset=UTF-8" } } } { cookies { } } { content-type "text/html" } - { content-charset utf8 } + { content-charset "UTF-8" } + { content-encoding utf8 } } ] [ read-response-test-1 lf>crlf diff --git a/basis/http/http.factor b/basis/http/http.factor index 6f898e949c..54866c745b 100644 --- a/basis/http/http.factor +++ b/basis/http/http.factor @@ -1,11 +1,11 @@ -! Copyright (C) 2003, 2008 Slava Pestov. +! Copyright (C) 2003, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel combinators math namespaces make assocs 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.crlf ascii io.encodings.8-bit.latin1 http.parsers base64 ; +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 ; IN: http CONSTANT: max-redirects 10 @@ -170,6 +170,7 @@ header cookies content-type content-charset +content-encoding body ; : ( -- response ) @@ -179,7 +180,7 @@ body ; "close" "connection" set-header now timestamp>http-string "date" set-header "Factor http.server" "server" set-header - latin1 >>content-charset + utf8 >>content-encoding V{ } clone >>cookies ; M: response clone @@ -221,5 +222,5 @@ TUPLE: post-data data params content-type content-encoding ; : parse-content-type ( content-type -- type encoding ) ";" split1 - parse-content-type-attributes "charset" swap at name>encoding - [ dup "text/" head? latin1 binary ? ] unless* ; + parse-content-type-attributes "charset" swap at + [ dup "text/" head? "UTF-8" and ] unless* ; diff --git a/basis/http/server/responses/responses.factor b/basis/http/server/responses/responses.factor index 3902b7f5e2..14527f5d68 100644 --- a/basis/http/server/responses/responses.factor +++ b/basis/http/server/responses/responses.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2008 Slava Pestov. +! Copyright (C) 2008, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: math.parser http accessors kernel xml.syntax xml.writer io io.streams.string io.encodings.utf8 ; @@ -8,7 +8,7 @@ IN: http.server.responses 200 >>code "Document follows" >>message - utf8 >>content-charset + utf8 >>content-encoding swap >>content-type swap >>body ; diff --git a/basis/http/server/server-tests.factor b/basis/http/server/server-tests.factor index 3dc97098a4..00e8710c70 100644 --- a/basis/http/server/server-tests.factor +++ b/basis/http/server/server-tests.factor @@ -4,16 +4,26 @@ IN: http.server.tests [ t ] [ [ \ + first ] [ <500> ] recover response? ] unit-test -[ "text/plain; charset=UTF-8" ] [ +[ "text/plain; charset=ASCII" ] [ "text/plain" >>content-type - utf8 >>content-charset + "ASCII" >>content-charset unparse-content-type ] unit-test -[ "text/xml" ] [ +[ "text/xml; charset=UTF-8" ] [ "text/xml" >>content-type - binary >>content-charset + unparse-content-type +] unit-test + +[ "image/jpeg" ] [ + + "image/jpeg" >>content-type + unparse-content-type +] unit-test + +[ "application/octet-stream" ] [ + unparse-content-type ] unit-test \ No newline at end of file diff --git a/basis/http/server/server.factor b/basis/http/server/server.factor index 131fe3fe18..bfb724ca9a 100644 --- a/basis/http/server/server.factor +++ b/basis/http/server/server.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2003, 2009 Slava Pestov. +! Copyright (C) 2003, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel accessors sequences arrays namespaces splitting vocabs.loader destructors assocs debugger continuations @@ -101,8 +101,10 @@ GENERIC: write-full-response ( request response -- ) tri ; : unparse-content-type ( request -- content-type ) - [ content-type>> "application/octet-stream" or ] [ content-charset>> ] bi - dup binary eq? [ drop ] [ encoding>name "; charset=" glue ] if ; + [ content-type>> ] [ content-charset>> ] bi + over "text/" head? [ "UTF-8" or ] when + [ "application/octet-stream" or ] dip + [ "; charset=" glue ] when* ; : ensure-domain ( cookie -- cookie ) [ @@ -133,7 +135,7 @@ M: response write-response ( respose -- ) M: response write-full-response ( request response -- ) dup write-response swap method>> "HEAD" = [ - [ content-charset>> encode-output ] + [ content-encoding>> encode-output ] [ write-response-body ] bi ] unless drop ; diff --git a/basis/http/server/static/static.factor b/basis/http/server/static/static.factor index f80a3cc7cd..6b65cd5fe4 100644 --- a/basis/http/server/static/static.factor +++ b/basis/http/server/static/static.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2004, 2009 Slava Pestov. +! Copyright (C) 2004, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: calendar kernel math math.order math.parser namespaces parser sequences strings assocs hashtables debugger mime.types @@ -16,11 +16,8 @@ TUPLE: file-responder root hook special allow-listings ; dup [ rfc822>timestamp ] when ; : modified-since? ( filename -- ? ) - request get modified-since dup [ - [ file-info modified>> ] dip after? - ] [ - 2drop t - ] if ; + request get modified-since dup + [ [ file-info modified>> ] dip after? ] [ 2drop t ] if ; : ( root hook -- responder ) file-responder new @@ -30,8 +27,8 @@ TUPLE: file-responder root hook special allow-listings ; : (serve-static) ( path mime-type -- response ) [ - [ binary &dispose ] dip - binary >>content-charset + [ binary &dispose ] dip + binary >>content-encoding ] [ drop file-info [ size>> ] [ modified>> ] bi ] 2bi [ "content-length" set-header ] From efe5e224830aeaf1dbfde78f4d30892d3a3fb996 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 13 Mar 2010 21:13:34 +1300 Subject: [PATCH 3/3] furnace.syndication: fix load error --- basis/furnace/syndication/syndication.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basis/furnace/syndication/syndication.factor b/basis/furnace/syndication/syndication.factor index d5d6c1cec8..b71abf6d86 100644 --- a/basis/furnace/syndication/syndication.factor +++ b/basis/furnace/syndication/syndication.factor @@ -1,8 +1,8 @@ -! Copyright (C) 2008 Slava Pestov. +! Copyright (C) 2008, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel sequences fry combinators syndication http.server.responses http.server.redirection furnace.actions -furnace.utilities ; +furnace.utilities io.encodings.utf8 ; IN: furnace.syndication GENERIC: feed-entry-title ( object -- string )