Skip to content

Commit 3139f40

Browse files
committed
CHANGE: keep / at the head of the HTTP request target (httpd module)
1 parent b4789fb commit 3139f40

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/modules/httpd.reb

+4-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ decode-target: wrap [
8080
][
8181
target
8282
][ any [result/file %""] ]
83-
if #"/" = first result/file [remove result/file]
8483
new-line/skip result/values true 2
8584
result
8685
]
@@ -238,7 +237,7 @@ sys/make-scheme [
238237
/local target path info index modified If-Modified-Since
239238
][
240239
target: ctx/inp/target
241-
target/file: path: join dirize ctx/config/root clean-path/only target/file
240+
target/file: path: join dirize ctx/config/root next clean-path/only target/file
242241
ctx/out/header/Date: to-idate/gmt now
243242
ctx/out/status: 200
244243
either exists? path [
@@ -352,13 +351,13 @@ sys/make-scheme [
352351
return false
353352
]
354353
dir: target/file
355-
path: find/match dir ctx/config/root
354+
path: join "/" find/match/tail dir ctx/config/root
356355

357356
try/except [
358357
out: make string! 2000
359358
append out ajoin [
360-
{<html><head><title>Index of /} path
361-
{</title></head><body bgcolor="white"><h1>Index of /} path
359+
{<html><head><title>Index of } path
360+
{</title></head><body bgcolor="white"><h1>Index of } path
362361
{</h1><hr><pre>^/}
363362
]
364363
unless empty? path [

src/tests/test-httpd.r3

+9-8
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,28 @@ http-server/config/actor 8081 [
4949
; TRUE = accepted, FALSE = refuse
5050
find [ 127.0.0.1 ] info/remote-ip
5151
]
52-
On-Header: func [ctx [object!]][
53-
switch ctx/inp/target/file [
54-
%form/ [
52+
On-Header: func [ctx [object!] /local path][
53+
path: ctx/inp/target/file
54+
switch path [
55+
%/form/ [
5556
; path rewrite...
5657
; http://localhost:8081/form/ is now same like http://localhost:8081/form.html
57-
ctx/inp/target/file: %form.html
58+
ctx/inp/target/file: %/form.html
5859
; request processing will continue
5960
]
60-
%form.htm
61-
%form.html [
61+
%/form.htm
62+
%/form.html [
6263
ctx/out/status: 301 ;= Moved Permanently
6364
ctx/out/header/Location: %/form/
6465
; request processing will stop with redirection response
6566
]
66-
%plain/ [
67+
%/plain/ [
6768
ctx/out/status: 200
6869
ctx/out/header/Content-Type: "text/plain; charset=UTF-8"
6970
ctx/out/content: "hello"
7071
; request processing will stop with response 200 serving the plain text content
7172
]
72-
%humans.txt [
73+
%/humans.txt [
7374
;@@ https://codeburst.io/all-about-humans-humans-txt-actually-f571d37f92d2
7475
;-- serving the content directly from the memory
7576
ctx/out/status: 200

0 commit comments

Comments
 (0)