Changeset 33896 in project


Ignore:
Timestamp:
03/19/17 20:02:53 (8 months ago)
Author:
sjamaan
Message:

Intarweb: Add chunking support for request parsing as well

Location:
release/4/intarweb/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/intarweb/trunk/intarweb.scm

    r33321 r33896  
    22;;; Intarweb is an improved HTTP library for Chicken
    33;;;
    4 ;; Copyright (c) 2008-2015, Peter Bex
     4;; Copyright (c) 2008-2017, Peter Bex
    55;; All rights reserved.
    66;;
     
    587587                 (headers (read-headers in)))
    588588        (let* ((wildcard (string=? uri-string "*"))
    589                (uri (and (not wildcard) (normalized-uri uri-string))))
     589               (uri (and (not wildcard) (normalized-uri uri-string)))
     590               ;; HTTP/1.0 has no chunking
     591               (port (if (and (or (> major 1) (>= minor 1))
     592                              (memq 'chunked
     593                                    (header-values
     594                                     'transfer-encoding headers)))
     595                         (chunked-input-port in)
     596                         in)))
    590597          ;; HTTP/1.1 allows several "things" as "URI" (RFC2616, 5.1.2):
    591598          ;; Request-URI = "*" | absoluteURI | abs_path | authority
     
    607614                             major: major minor: minor
    608615                             headers: headers
    609                              port: in)))))))
     616                             port: port)))))))
    610617
    611618(define request-parsers   ; order matters here
  • release/4/intarweb/trunk/tests/run.scm

    r32591 r33896  
    866866      (test (uri-reference "/path/to/stuff?arg1=val1&arg2=val2") (request-uri req))
    867867      (test (headers '()) (request-headers req)))
    868     (test 'PUT (request-method (test-read-request "PUT /path HTTP/1.0\r\n"))))
     868    (test 'PUT (request-method (test-read-request "PUT /path HTTP/1.0\r\n")))
     869    (let ((req (test-read-request "POST / HTTP/1.0\r\nTransfer-Encoding: chunked\r\n\r\n3\r\nfoo\r\na\r\n1234567890\r\n")))
     870      (test "Chunking ignored"
     871            "3\r\nfoo\r\na\r\n1234567890\r\n"
     872            (read-string #f (request-port req)))))
    869873  (test-group "HTTP/1.1" ; No need to test all things we test for 1.0
    870874    (test "Asterisk is treated specially and returns #f uri"
     
    899903                 ;; This errors when the limit is hit, not when it is exceeded
    900904                 (parameterize ((http-urlencoded-request-data-limit 7))
    901                    (read-urlencoded-request-data req)))))
     905                   (read-urlencoded-request-data req))))
     906   (let ((req (test-read-request "POST / HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n3\r\nfoo\r\na\r\n1234567890\r\n0\r\n\r\n")))
     907      (test "Chunking"
     908            "foo1234567890"
     909            (read-string #f (request-port req)))))
    902910  (test-group "Invalid protocols"
    903911    (test-error "Total cruft is unrecognised"
Note: See TracChangeset for help on using the changeset viewer.