Skip to content

Commit 242ceba

Browse files
committed
FIX: HTTP protocol - limit input data according Content-Length
fixes: Oldes/Rebol-issues#2386
1 parent 07379a6 commit 242ceba

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/mezz/prot-http.r

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ REBOL [
1111
}
1212
Name: 'http
1313
Type: 'module
14-
Version: 0.3.3
14+
Version: 0.3.4
1515
Date: 25-Feb-2020
1616
File: %prot-http.r
1717
Purpose: {
@@ -32,6 +32,7 @@ REBOL [
3232
0.3.1 13-Feb-2020 "Oldes" "FEAT: Possible auto conversion to text if found charset specification in content-type"
3333
0.3.2 25-Feb-2020 "Oldes" "FIX: Properly handling chunked data"
3434
0.3.3 25-Feb-2020 "Oldes" "FEAT: support for read/binary and write/binary to force raw data result"
35+
0.3.4 26-Feb-2020 "Oldes" "FIX: limit input data according Content-Length (#issues/2386)"
3536
]
3637
]
3738

@@ -617,10 +618,10 @@ check-data: func [port /local headers res data available out chunk-size pos trai
617618
]
618619
]
619620
integer? headers/content-length [
620-
port/data: conn/data
621-
either headers/content-length <= length? port/data [
621+
either headers/content-length <= length? conn/data [
622622
state/state: 'ready
623-
conn/data: make binary! 32000 ;@@ Oldes: why not just none?
623+
port/data: copy/part conn/data headers/content-length
624+
conn/data: none
624625
res: state/awake make event! [type: 'custom port: port code: 0]
625626
][
626627
;Awake from the WAIT loop to prevent timeout when reading big data. --Richard

src/tests/test-httpd.r3

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ my-actor: object [
3838
ctx/out/header/Location: %/form/
3939
; request processing will stop with redirection response
4040
]
41+
%plain/ [
42+
ctx/out/status: 200
43+
ctx/out/header/Content-Type: "text/plain; charset=UTF-8"
44+
ctx/out/content: "hello"
45+
; request processing will stop with response 200 serving the plain text content
46+
]
4147
]
4248
]
4349
On-Post-Received: func [ctx [object!]][

0 commit comments

Comments
 (0)