Skip to content

Commit

Permalink
FEAT: HTTPD server now have ON-ACCEPT actor which can be used to limi…
Browse files Browse the repository at this point in the history
…t connection to specified IPs only
  • Loading branch information
Oldes committed Apr 2, 2019
1 parent 7ba3dc2 commit ead47c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/modules/httpd.r3
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Rebol [
TODO: {
* support for multidomain serving using `Host` header field
* add support for other methods - PUT, DELETE, TRACE, CONNECT, OPTIONS?
* limit connections per IP
* better error handling
* standard access log
* add list-dir action which shows content of a directory, if allowed
Expand Down Expand Up @@ -117,6 +116,7 @@ sys/make-scheme [
close port/locals/subport
]

On-Accept: func [ctx [object!]][ true ]
On-Header: func [ctx [object!]][] ;= placeholder; user can use it for early request processing

On-Get: func [
Expand Down Expand Up @@ -495,8 +495,14 @@ sys/make-scheme [

New-Client: func[port [port!] /local client info err][
client: first port
client/awake: :Awake-Client
info: query client
unless Actor/On-Accept info [
; connection not allowed
sys/log/info 'HTTPD ["Client not accepted:^[[22m" info/remote-ip]
close client
return false
]
client/awake: :Awake-Client
client/locals: make object! [
state: none
parent: port
Expand Down
2 changes: 1 addition & 1 deletion src/tests/httpd-root/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</head>
<body>
<h1>Just a simple test form</h1>
<form action="form.html" method="post">
<form action="/result/" method="post">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
Expand Down
6 changes: 5 additions & 1 deletion src/tests/test-httpd.r3
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ do %../modules/httpd.r3
system/options/log/httpd: 3 ; for verbose output

my-actor: object [
On-Accept: func [info [object!]][
; allow only connections from localhost
; TRUE = accepted, FALSE = refuse
find [ 127.0.0.1 ] info/remote-ip
]
On-Header: func [ctx [object!]][
switch ctx/inp/target/file [
%form/ [
Expand All @@ -34,7 +39,6 @@ my-actor: object [
; request processing will stop with redirection response
]
]
? ctx
]
On-Post-Received: func [ctx [object!]][
ctx/out/header/Content-Type: "text/html; charset=UTF-8"
Expand Down

0 comments on commit ead47c0

Please sign in to comment.