[plt-scheme] BASE64(bytes) CR LF

From: Ray Racine (ray.racine at comcast.net)
Date: Mon Sep 24 23:29:29 EDT 2007

Currently MzScheme does ...
> (require (lib "base64.ss" "net"))
> (base64-encode (string->bytes/utf-8 "ray"))

I would have expected #"cmF5".

Anyone know why it adds the extra \r\n suffix?

I don't see any advantage gained by it. 

Currently I must strip it off when I use a base64-encoded value as a
http header value otherwise \r\n\r\n prematurely terminates the http
message and causes havoc with the http protocol.

(let* (
  (hash64 (bytes->string/utf-8 
		(let ((enc (base64-encode (md5 bytes #f))))
                      (subbytes enc 0 (- (bytes-length enc) 2)))))
                        ;; base64-encode adds a bogus \r\n 
  (mime "binary/octet-stream")
  (datetime (rfc2822-date))
  (url (make-object-url s3-resource))
  (http-headers (list (date-header datetime)
                    (content-type mime)
                    (content-md5 hash64)
      		    (authorization-header credentials 
                    (aws-s3-auth-str "PUT" hash64 mime datetime '()
                        (s3-resource->string s3-resource))))))
(s3-response-from-port (s3-put url bytes http-headers))))

The s3-put procedure uses ("url.ss" "net") put-impure-port which
implicitly adds the \r\n to a given http-header making the base64 added 
\r\n redundant and even unwanted.

Posted on the users mailing list.