diff --git a/basis/http/server/server-tests.factor b/basis/http/server/server-tests.factor index da43c0e0bc..cfadfeb217 100644 --- a/basis/http/server/server-tests.factor +++ b/basis/http/server/server-tests.factor @@ -1,6 +1,6 @@ USING: accessors continuations http http.server io.encodings.utf8 io.encodings.binary io.streams.string kernel -math sequences tools.test urls ; +math peg sequences tools.test urls ; IN: http.server.tests [ t ] [ [ \ + first ] [ <500> ] recover response? ] unit-test @@ -62,3 +62,12 @@ IN: http.server.tests "\r\n\r\n\r\nGET / HTTP/1.0\r\n\r\n" [ read-request ] with-string-reader ] unit-test + +! Don't rethrow parse-errors with an empty request string. They are +! expected from certain browsers when the server serves a certificate +! that the browser can't verify. +{ } [ 0 "" f handle-client-error ] unit-test + +[ + 0 "not empty" f handle-client-error +] [ parse-error? ] must-fail-with diff --git a/basis/http/server/server.factor b/basis/http/server/server.factor index 6b69d36503..4b9cbc5fbc 100644 --- a/basis/http/server/server.factor +++ b/basis/http/server/server.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: kernel accessors sequences arrays namespaces splitting vocabs.loader destructors assocs debugger continuations -combinators vocabs.refresh tools.time math math.parser present -vectors hashtables +combinators combinators.short-circuit vocabs.refresh tools.time math math.parser +present vectors hashtables io io.sockets io.sockets.secure @@ -29,6 +29,7 @@ html.streams html mime.types math.order +peg xml.writer vocabs ; FROM: mime.multipart => parse-multipart ; @@ -66,7 +67,7 @@ upload-limit [ 200,000,000 ] initialize upload-limit get [ min ] when* limited-input binary decode-input parse-multipart-form-data parse-multipart ; - + : read-content ( request -- bytes ) "content-length" header string>number read ; @@ -285,13 +286,18 @@ LOG: httpd-benchmark DEBUG TUPLE: http-server < threaded-server ; +: handle-client-error ( error -- ) + dup { [ parse-error? ] [ got>> empty? ] } 1&& [ drop ] [ rethrow ] if ; + M: http-server handle-client* drop [ - ?refresh-all - request-limit get limited-input - [ read-request ] ?benchmark - [ do-request ] ?benchmark - [ do-response ] ?benchmark + [ + ?refresh-all + request-limit get limited-input + [ read-request ] ?benchmark + [ do-request ] ?benchmark + [ do-response ] ?benchmark + ] [ handle-client-error ] recover ] with-destructors ; : ( -- server )