http.server: handle certain parse-errors from the peg vocab
Browsers that can't verify the certificate doesn't send any request at all which causes parse-errors to be unnecessarily thrown and logged.db4
parent
1ee9a8ea13
commit
84663ca054
|
@ -1,6 +1,6 @@
|
||||||
USING: accessors continuations http http.server
|
USING: accessors continuations http http.server
|
||||||
io.encodings.utf8 io.encodings.binary io.streams.string kernel
|
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
|
IN: http.server.tests
|
||||||
|
|
||||||
[ t ] [ [ \ + first ] [ <500> ] recover response? ] unit-test
|
[ 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"
|
"\r\n\r\n\r\nGET / HTTP/1.0\r\n\r\n"
|
||||||
[ read-request ] with-string-reader
|
[ read-request ] with-string-reader
|
||||||
] unit-test
|
] 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 <parse-error> handle-client-error ] unit-test
|
||||||
|
|
||||||
|
[
|
||||||
|
0 "not empty" f <parse-error> handle-client-error
|
||||||
|
] [ parse-error? ] must-fail-with
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel accessors sequences arrays namespaces splitting
|
USING: kernel accessors sequences arrays namespaces splitting
|
||||||
vocabs.loader destructors assocs debugger continuations
|
vocabs.loader destructors assocs debugger continuations
|
||||||
combinators vocabs.refresh tools.time math math.parser present
|
combinators combinators.short-circuit vocabs.refresh tools.time math math.parser
|
||||||
vectors hashtables
|
present vectors hashtables
|
||||||
io
|
io
|
||||||
io.sockets
|
io.sockets
|
||||||
io.sockets.secure
|
io.sockets.secure
|
||||||
|
@ -29,6 +29,7 @@ html.streams
|
||||||
html
|
html
|
||||||
mime.types
|
mime.types
|
||||||
math.order
|
math.order
|
||||||
|
peg
|
||||||
xml.writer
|
xml.writer
|
||||||
vocabs ;
|
vocabs ;
|
||||||
FROM: mime.multipart => parse-multipart ;
|
FROM: mime.multipart => parse-multipart ;
|
||||||
|
@ -285,13 +286,18 @@ LOG: httpd-benchmark DEBUG
|
||||||
|
|
||||||
TUPLE: http-server < threaded-server ;
|
TUPLE: http-server < threaded-server ;
|
||||||
|
|
||||||
|
: handle-client-error ( error -- )
|
||||||
|
dup { [ parse-error? ] [ got>> empty? ] } 1&& [ drop ] [ rethrow ] if ;
|
||||||
|
|
||||||
M: http-server handle-client*
|
M: http-server handle-client*
|
||||||
drop [
|
drop [
|
||||||
|
[
|
||||||
?refresh-all
|
?refresh-all
|
||||||
request-limit get limited-input
|
request-limit get limited-input
|
||||||
[ read-request ] ?benchmark
|
[ read-request ] ?benchmark
|
||||||
[ do-request ] ?benchmark
|
[ do-request ] ?benchmark
|
||||||
[ do-response ] ?benchmark
|
[ do-response ] ?benchmark
|
||||||
|
] [ handle-client-error ] recover
|
||||||
] with-destructors ;
|
] with-destructors ;
|
||||||
|
|
||||||
: <http-server> ( -- server )
|
: <http-server> ( -- server )
|
||||||
|
|
Loading…
Reference in New Issue