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
|
||||
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 <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.
|
||||
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 ;
|
||||
|
||||
: <http-server> ( -- server )
|
||||
|
|
Loading…
Reference in New Issue