proxy/http-test.ss
(module http-test mzscheme
  
  (require (planet "test.ss" ("schematics" "schemeunit.plt" 2)))
  (require "http.ss")
  
  (provide http-tests)
  
  (define http-tests
    (test-suite
     "All tests for http"

     (test-case
      "parse-request-line"
      (let-values (([line method url major minor]
                    (parse-request-line
                     (open-input-bytes #"GET / HTTP/1.0"))))
        (check bytes=? line #"GET / HTTP/1.0")
        (check bytes=? method #"GET")
        (check bytes=? url #"/")
        (check bytes=? major #"1")
        (check bytes=? minor #"0")))

     (test-case
      "parse-status-line"
      (let-values (([line major minor code message]
                    (parse-status-line
                     (open-input-bytes #"HTTP/1.0 200 OK"))))
        (check bytes=? line #"HTTP/1.0 200 OK")
        (check bytes=? code #"200")
        (check bytes=? message #"OK")
        (check bytes=? major #"1")
        (check bytes=? minor #"0")))
     
     (test-case
      "parse-headers"
      (let* ([h (make-hash-table 'equal)]
            [l (parse-headers
                (open-input-bytes #"Host: untyped.com\r\nCat: Tabby\r\n\r\n")
                h)])
        (check-equal? l (list #"Host: untyped.com" #"Cat: Tabby"))
        (check-equal? (hash-table-get h #"Host") #"untyped.com")
        (check-equal? (hash-table-get h #"Cat") #"Tabby")))

     (test-case
      "transfer-body w/ content length"
      (let* ([h (make-hash-table 'equal)]
             [content (make-bytes 10 97)]
             [in (open-input-bytes content)]
             [out (open-output-bytes)])
        (hash-table-put! h #"Content-Length" content)
        (transfer-body in out h)
        (check-equal? (get-output-bytes out) #"aaaaaaaaaa\r\n")))

     (test-case
      "transfer-body w/o content length"
      (let* ([h (make-hash-table 'equal)]
             [content (make-bytes 10 97)]
             [in (open-input-bytes content)]
             [out (open-output-bytes)])
        (transfer-body in out h)
        (check-equal? (get-output-bytes out) #"aaaaaaaaaa\r\n")))
     ))
  )