1
1
Rebol [
2
2
Title: "HTTPD Scheme"
3
- Date: 10-May -2020
3
+ Date: 02-Jul -2020
4
4
Author: ["Andreas Bolka" "Christopher Ross-Gill" "Oldes" ]
5
5
File: %httpd.r3
6
6
Name: 'httpd
7
7
Type: 'module
8
- Version: 0.5 .0
8
+ Version: 0.6 .0
9
9
Exports: [http-server decode-target to-CLF-idate]
10
10
Rights: http://opensource.org/licenses/Apache-2.0
11
11
Purpose: {
@@ -16,6 +16,7 @@ Rebol [
16
16
* using _actors_ for main actions which may be customized
17
17
* implemented `keep-alive` behaviour
18
18
* sends `Not modified` response if file was not modified in given time
19
+ * client can stop server
19
20
}
20
21
TODO: {
21
22
* support for multidomain serving using `Host` header field
@@ -31,6 +32,7 @@ Rebol [
31
32
https://gist.github.com/rgchris/73510e7d643eb0a6b9fa69b849cd9880}
32
33
01-Apr-2019 "Oldes" {Rewritten to be usable in real life situations.}
33
34
10-May-2020 "Oldes" {Implemented directory listing, logging and multipart POST processing}
35
+ 02-Jul-2020 "Oldes" {Added possibility to stop server and return data from client (useful for OAuth2)}
34
36
]
35
37
]
36
38
@@ -570,14 +572,14 @@ sys/make-scheme [
570
572
#"^/"
571
573
]
572
574
prin msg
573
- if file? ctx/config/ log-access [
574
- write /append ctx /config/log-access msg
575
+ if file? file: select ctx/config ' log-access [
576
+ write /append file msg
575
577
]
576
578
if all [
577
579
ctx/out/status >= 400
578
- file? ctx/config/ log-errors
580
+ file? file: select ctx/config ' log-errors
579
581
][
580
- write /append ctx /config/log-errors msg
582
+ write /append file msg
581
583
]
582
584
][
583
585
print "** Failed to write a log"
@@ -701,9 +703,12 @@ sys/make-scheme [
701
703
sys/log/debug 'HTTPD ["Awake (server):^[ [22m" event/type ]
702
704
switch event/type [
703
705
ACCEPT [ New-Client event/port ]
704
- CLOSE [ ]
706
+ CLOSE [
707
+ close event/port
708
+ close event/port/locals/parent
709
+ ]
705
710
]
706
- false
711
+ true
707
712
]
708
713
709
714
@@ -739,6 +744,7 @@ sys/make-scheme [
739
744
]
740
745
config: none
741
746
timeout: none
747
+ done?: none
742
748
requests: 0 ; number of already served requests per connection
743
749
]
744
750
;? port
@@ -778,6 +784,11 @@ sys/make-scheme [
778
784
;try [remove find clients port]
779
785
]
780
786
sys/log/debug 'HTTPD ["Ports open:" length? clients]
787
+ if all [ctx/done? zero? length? clients][
788
+ sys/log/info 'HTTPD "Server's job done, closing initiated"
789
+ ctx/parent/data: ctx/done?
790
+ Awake-Server make event! [type: 'CLOSE port: ctx/parent ]
791
+ ]
781
792
]
782
793
783
794
Check-Clients : func [
@@ -821,15 +832,21 @@ http-server: function [
821
832
append server/locals/config spec
822
833
]
823
834
824
- ? server/locals/config
835
+ unless system/options/quiet [
836
+ ? server/locals/config
837
+ ]
825
838
826
839
if actor [
827
- if object? actions [ actions: body-of actions ]
828
- append server/actor actions
840
+ append server/actor either block? actions [
841
+ reduce /no-set actions
842
+ ][ body-of actions ]
829
843
]
830
844
unless no-wait [
831
845
forever [
832
- wait [server 15 ]
846
+ p: wait [server server/locals/subport 15 ]
847
+ if all [port? p not open? p] [
848
+ return p/data
849
+ ]
833
850
server/scheme/Check-Clients server
834
851
]
835
852
]
0 commit comments