[version 0.11.0 ediware**20071001170007] { hunk ./CHANGELOG.txt 1 +Version 0.11.0 +2007-10-01 +Added *TEXT-CONTENT-TYPES* and *BODY-FORMAT-FUNCTION* (suggested by Peter Eddy) + hunk ./doc/index.html 69 +
  • *text-content-types* +
  • *body-format-function* hunk ./doc/index.html 646 -The current version is 0.10.2. Drakma can be installed +The current version is 0.11.0. Drakma can be installed hunk ./doc/index.html 964 -type, Drakma will try to return it as a Lisp string. It'll first -check if the 'Content-Type' header denotes an encoding (charset) to be -used, or otherwise it will use -the external-format-in (the default is the value -of *DRAKMA-DEFAULT-EXTERNAL-FORMAT*) +type, Drakma will try to return it as a Lisp string. +It'll first check if the 'Content-Type' header denotes an encoding +(charset) to be used, or otherwise it will use the external-format-in +(the default is the value +of *DRAKMA-DEFAULT-EXTERNAL-FORMAT*) hunk ./doc/index.html 973 -as an array of octets. -If the message body doesn't have a text content type or if -force-binary is true, the body is always returned -as an array of octets. +as an array of octets. If the message body doesn't have a text +content type or if +force-binary +is true, the body is always returned as an array of octets. (But +see *TEXT-CONTENT-TYPES* +and *BODY-FORMAT-FUNCTION*.) hunk ./doc/index.html 1042 + + +


    [Special variable]
    *text-content-types* +


    + +A list of conses which are used by the default value of *BODY-FORMAT-FUNCTION* to decide +whether a 'Content-Type' header denotes text content. The car and cdr +of each cons should each be a string or NIL. A content type matches +one of these entries (and thus denotes text) if the type part is +STRING-EQUAL +to the car or if the car is NIL and if the subtype part +is STRING-EQUAL +to the cdr or if the cdr is NIL. +

    +The initial value of this variable is the list +

    +(("text" . nil))
    +
    +which means that every content type that starts with "text/" is +regarded as text, no matter what the subtype is. + +
    + + + + + +


    [Special variable]
    *body-format-function* +


    + +A function which determines whether the content body returned by the +server is text and should be treated as such or not. The function is +called after the request headers have been read +and it must accept two arguments, headers +and external-format-in, where headers is like the +third return value of HTTP-REQUEST while external-format-in is the +HTTP-REQUEST argument of the +same name. It should return NIL if the body should be +regarded as binary content, or +a FLEXI-STREAMS external +format (which will be used to read the body) otherwise. +

    +This function will only be called if +the force-binary +argument to HTTP-REQUEST is NIL. +

    +The initial value of this variable is a function which uses +*TEXT-CONTENT-TYPES* +to determine whether the body is text and then proceeds as described +in the HTTP-REQUEST +documentation entry. + +

    + + + hunk ./doc/index.html 1468 -$Header: /usr/local/cvsrep/drakma/doc/index.html,v 1.77 2007/09/29 14:03:27 edi Exp $ +$Header: /usr/local/cvsrep/drakma/doc/index.html,v 1.78 2007/10/01 08:04:06 edi Exp $ hunk ./drakma.asd 2 -;;; $Header: /usr/local/cvsrep/drakma/drakma.asd,v 1.40 2007/09/29 14:03:24 edi Exp $ +;;; $Header: /usr/local/cvsrep/drakma/drakma.asd,v 1.41 2007/10/01 08:04:04 edi Exp $ hunk ./drakma.asd 37 -(defvar *drakma-version-string* "0.10.2" +(defvar *drakma-version-string* "0.11.0" hunk ./packages.lisp 2 -;;; $Header: /usr/local/cvsrep/drakma/packages.lisp,v 1.20 2007/09/18 14:27:43 edi Exp $ +;;; $Header: /usr/local/cvsrep/drakma/packages.lisp,v 1.21 2007/10/01 08:04:04 edi Exp $ hunk ./packages.lisp 36 - (:export :*drakma-default-external-format* + (:export :*body-format-function* + :*drakma-default-external-format* hunk ./packages.lisp 40 + :*text-content-types* hunk ./request.lisp 2 -;;; $Header: /usr/local/cvsrep/drakma/request.lisp,v 1.48 2007/09/29 14:03:25 edi Exp $ +;;; $Header: /usr/local/cvsrep/drakma/request.lisp,v 1.49 2007/10/01 08:04:04 edi Exp $ hunk ./request.lisp 32 +(defun determine-body-format (headers external-format-in) + "The default function used by Drakma to determine how the content +body is to be read. See the docstring of *BODY-FORMAT-FUNCTION* for +more info." + (handler-case + (let ((transfer-encodings (header-value :transfer-encoding headers)) + (content-encodings (header-value :content-encoding headers))) + (when transfer-encodings + (setq transfer-encodings (split-tokens transfer-encodings))) + (when content-encodings + (setq content-encodings (split-tokens content-encodings))) + (multiple-value-bind (type subtype params) + (get-content-type headers) + (when (and (text-content-type-p type subtype) + (null (set-difference transfer-encodings + '("chunked" "identity") + :test #'equalp)) + (null (set-difference content-encodings + '("identity") + :test #'equalp))) + (let* ((charset (parameter-value "charset" params)) + (name (cond (charset (intern (string-upcase charset) + :keyword)) + (t external-format-in)))) + (make-external-format name :eol-style :lf))))) + (error (condition) + (warn "Problems determining charset \(falling back to binary):~%~A" + condition)))) + hunk ./request.lisp 620 - (let ((transfer-encodings (header-value :transfer-encoding headers)) - (content-encodings (header-value :content-encoding headers))) + (let ((transfer-encodings (header-value :transfer-encoding headers))) hunk ./request.lisp 623 - (when content-encodings - (setq content-encodings (split-tokens content-encodings))) hunk ./request.lisp 625 - (flexi-stream-stream http-stream)) t)) - (unless force-binary - (handler-case - (multiple-value-bind (type subtype params) - (get-content-type headers) - (declare (ignore subtype)) - (when (and (string-equal type "text") - (null (set-difference transfer-encodings - '("chunked" "identity") - :test #'equalp)) - (null (set-difference content-encodings - '("identity") - :test #'equalp))) - (let* ((charset (parameter-value "charset" params)) - (name (cond (charset (intern (string-upcase charset) - :keyword)) - (t external-format-in)))) - (setq external-format-body - (make-external-format name :eol-style :lf))))) - (error (condition) - (warn "Problems determining charset ~ -\(falling back to binary):~%~A" - condition))))) - (cond (external-format-body - (setf (flexi-stream-external-format http-stream) - external-format-body)) - (t (setf (flexi-stream-element-type http-stream) 'octet))) + (flexi-stream-stream http-stream)) t))) + (when (setq external-format-body + (and (not force-binary) + (funcall *body-format-function* + headers external-format-in))) + (setf (flexi-stream-external-format http-stream) + external-format-body)) hunk ./specials.lisp 2 -;;; $Header: /usr/local/cvsrep/drakma/specials.lisp,v 1.17 2007/06/25 10:25:15 edi Exp $ +;;; $Header: /usr/local/cvsrep/drakma/specials.lisp,v 1.18 2007/10/01 08:04:04 edi Exp $ hunk ./specials.lisp 78 + +(defvar *text-content-types* '(("text" . nil)) + "A list of conses which are used by DETERMINE-BODY-FORMAT to decide +whether a `Content-Type' header denotes text content. The car and cdr +of each cons should each be a string or NIL. A content type matches +one of these entries \(and thus denotes text) if the type part is +STRING-EQUAL to the car or if the car is NIL and if the subtype part +is STRING-EQUAL to the cdr or if the cdr is NIL.") + +(defvar *body-format-function* 'determine-body-format + "A function which determines whether the content body returned by +the server is text and should be treated as such or not. The function +is called after the request headers have been read and it must accept +two arguments, HEADERS and EXTERNAL-FORMAT-IN where HEADERS is like +the third return value of HTTP-REQUEST while EXTERNAL-FORMAT-IN is the +HTTP-REQUEST argument of the same name. It should return NIL if the +body should be regarded as binary content, or a FLEXI-STREAMS external +format \(which will be used to read the body) otherwise. + +This function will only be called if the FORCE-BINARY argument to +HTTP-REQUEST was NIL.") hunk ./util.lisp 2 -;;; $Header: /usr/local/cvsrep/drakma/util.lisp,v 1.31 2007/06/25 10:25:15 edi Exp $ +;;; $Header: /usr/local/cvsrep/drakma/util.lisp,v 1.32 2007/10/01 08:04:04 edi Exp $ hunk ./util.lisp 266 + +(defun text-content-type-p (type subtype) + "Returns a true value iff the combination of TYPE and SUBTYPE +matches an entry of *TEXT-CONTENT-TYPES*. See docstring of +*TEXT-CONTENT-TYPES* for more info." + (loop for (candidate-type . candidate-subtype) in *text-content-types* + thereis (and (or (null candidate-type) + (string-equal type candidate-type)) + (or (null candidate-subtype) + (string-equal subtype candidate-subtype))))) }