Changeset 29915 in project


Ignore:
Timestamp:
10/13/13 19:55:01 (8 years ago)
Author:
sjamaan
Message:

intarweb: Get rid of annoying 'unknown protocol( line)' message and return #f if no response or request can be read due to EOF right at the start

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

Legend:

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

    r29894 r29915  
    559559
    560560(define (read-request inport)
    561   (let* ((line (safe-read-line inport))
    562          ;; A bit ugly, but simpler than the alternatives
    563          (line (if (eof-object? line) "" line)))
    564     ;; Try each parser in turn to process the request-line.
    565     ;; A parser returns either #f or a request object
    566     (let loop ((parsers (request-parsers)))
    567       (if (null? parsers)
    568           (signal-http-condition "Unknown protocol line" (list line)
    569                                  'unknown-protocol-line 'line line)
    570           (or ((car parsers) line inport) (loop (cdr parsers)))))))
     561  (let ((line (safe-read-line inport)))
     562    (and (not (eof-object? line))
     563         ;; Try each parser in turn to process the request-line.
     564         ;; A parser returns either #f or a request object
     565         (let loop ((parsers (request-parsers)))
     566           (if (null? parsers)
     567               (signal-http-condition "Unknown protocol line" (list line)
     568                                      'unknown-protocol-line 'line line)
     569               (or ((car parsers) line inport) (loop (cdr parsers))))))))
    571570
    572571;;;;;;;;;;;;;;;;;;;;;;;;;;;
     
    890889
    891890(define (read-response inport)
    892   (let* ((line (safe-read-line inport))
    893          (line (if (eof-object? line) "" line)))
    894     (let loop ((parsers (response-parsers)))
    895       (if (null? parsers)
    896           (signal-http-condition "Unknown protocol" (list line)
    897                                  'unknown-protocol-line 'line line)
    898           (or ((car parsers) line inport) (loop (cdr parsers)))))))
     891  (let ((line (safe-read-line inport)))
     892    (and (not (eof-object? line))
     893         (let loop ((parsers (response-parsers)))
     894           (if (null? parsers)
     895               (signal-http-condition "Unknown protocol line" (list line)
     896                                      'unknown-protocol-line 'line line)
     897               (or ((car parsers) line inport) (loop (cdr parsers))))))))
    899898
    900899)
  • release/4/intarweb/trunk/tests/run.scm

    r29883 r29915  
    808808                                       (and (string=? line "bar") 'bar)))))
    809809    (test-error* (http unknown-protocol-line) (test-read-request "qux"))
    810     (test-error* (http unknown-protocol-line) (test-read-request ""))
     810    (test #f (test-read-request ""))
    811811    (test 'foo (test-read-request "foo"))
    812812    (test 'bar (test-read-request "bar")))
     
    959959            "Contents"
    960960            (read-string #f (response-port res))))
     961    (test-error* (http unknown-protocol-line) (test-read-response "qux"))
     962    (test #f (test-read-request ""))
    961963    (test-error "Response line limit exceeded gives error"
    962964                (parameterize ((http-line-limit 5))
Note: See TracChangeset for help on using the changeset viewer.