[plt-dev] Re: web-server support for arbitrary content in POST requests?

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Mon Feb 22 12:50:26 EST 2010

> 2. You would not require any changes if you used a PUT or put your
> gzip'd data in a field of the POST or as a file transfer.

But the experiment I'm doing here suggests that the second approach
--- gzipping data in a field --- won't be effective:

(require file/gzip

(define (gzip-bytes bytes)
  (let ([op (open-output-bytes)])
    (gzip-through-ports (open-input-bytes bytes) op #f 0)
    (get-output-bytes op)))

(define (compare-compression path)
  (let* ([original-bytes (port->bytes (open-input-file path))]
           (apply string
                  (map integer->char
                       (bytes->list (gzip-bytes original-bytes))))]
          (uri-encode content-without-uri-encoding)])
    (list (bytes-length original-bytes)
          (string-length content-without-uri-encoding)
          (string-length content-with-uri-encoding))))

This is some code to compare sizes of respective encodings.  For example:

> (compare-compression "/usr/share/dict/words")
(2486813 751990 2981555)

> (compare-compression "/Users/dyoo/work/moby/support/js/runtime/compressed-runtime.js")
(164975 36309 144502)

The first number is the byte length of the original content, the
second is the string length of the gzipped content, and the third is
the length after uri-encoding.  Whatever major savings I would have
gotten from gzip compression gets squashed under the expansion due to
uri-encoding of field values.  That's why I want control over how my
POST data is encoded.

Posted on the dev mailing list.