aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrahflow <drahflow@gmx.de>2017-03-06 08:03:36 +0100
committerDrahflow <drahflow@gmx.de>2017-03-06 08:03:36 +0100
commit54029d848bfd7bc0972da2ba46589997fa214238 (patch)
tree72a09c599a45e8220dd05df205c1375fc0e8707a
parent92ee378b02c8e28c04843d1c936d7aeb702766a8 (diff)
Handle POST requests more robustly
-rw-r--r--elymas/lib/net/alg/http.ey30
-rw-r--r--examples/working-loaded/httpServer.test3
2 files changed, 23 insertions, 10 deletions
diff --git a/elymas/lib/net/alg/http.ey b/elymas/lib/net/alg/http.ey
index 48b851f..2307b61 100644
--- a/elymas/lib/net/alg/http.ey
+++ b/elymas/lib/net/alg/http.ey
@@ -47,16 +47,26 @@
headers .?Content-Length not {
requestParsed
} {
- headers .Content-Length txt .consume .u ==contentLength
-
- # FIXME: Must change *=in and =*end here to correctly process further incoming data
- { body -01 cat =body
- body len _ ::inputBufferLimit gt { "" =body :close } rep
- contentLength eq { requestParsed } rep
- ""
- } =in
-
- inBuffer in =inBuffer
+ headers .Content-Length "^\\d+$" regex not {
+ "" =inBuffer :close
+ } {
+ headers .Content-Length txt .consume .u ==contentLength
+
+ { body -01 cat =body
+ body len _ ::inputBufferLimit gt { "" =body :close } rep
+ contentLength ge {
+ contentLength body str .postfix ==afterBody
+ contentLength body str .prefix =body
+ requestParsed
+
+ afterBody
+ } {
+ ""
+ } ? *
+ } =in
+
+ inBuffer in =inBuffer
+ } ? *
} ? *
}
{ 1 } {
diff --git a/examples/working-loaded/httpServer.test b/examples/working-loaded/httpServer.test
index 47ff274..781364c 100644
--- a/examples/working-loaded/httpServer.test
+++ b/examples/working-loaded/httpServer.test
@@ -9,6 +9,9 @@ net .alg .httpServer "+" via
} { :url "/test" eq } {
"<html><body>Test!</body></html>"
"text/html" :ok
+ } { :url "/post" eq } {
+ "<html><body>" :body "</body></html>" cat cat
+ "text/html" :ok
}
] conds
} +request