aboutsummaryrefslogtreecommitdiff
path: root/lib/http/testdata
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-02-05 19:26:29 +0700
committerShulhan <ms@kilabit.info>2026-02-05 19:26:29 +0700
commit3734420eec485bca8c18243741e1ad2a683515b7 (patch)
treec08f208e76f516048e07e982fa712daafc98cce3 /lib/http/testdata
parentf40153cfb1cd859538aeaad17f0a243b4ef0c52c (diff)
downloadpakakeh.go-3734420eec485bca8c18243741e1ad2a683515b7.tar.xz
lib/http: handle file system with canonical directory end with slash "/"
Previously, if request to directory does not end with "/", the HTTP server will return the index.html of that directory. This cause relative link inside the index.html broken when visited from browser. This changes make the request to directory always end with "/" by redirecting the request with status 303 Found.
Diffstat (limited to 'lib/http/testdata')
-rw-r--r--lib/http/testdata/Server_HandleFS/b.html6
-rw-r--r--lib/http/testdata/Server_HandleFS/dir/index.html6
-rw-r--r--lib/http/testdata/Server_HandleFS/index.html6
-rw-r--r--lib/http/testdata/Server_HandleFS_test.txt98
4 files changed, 103 insertions, 13 deletions
diff --git a/lib/http/testdata/Server_HandleFS/b.html b/lib/http/testdata/Server_HandleFS/b.html
new file mode 100644
index 00000000..aa8d367a
--- /dev/null
+++ b/lib/http/testdata/Server_HandleFS/b.html
@@ -0,0 +1,6 @@
+<!doctype html>
+<html>
+ <head>
+ <title>/b.html</title>
+ </head>
+</html>
diff --git a/lib/http/testdata/Server_HandleFS/dir/index.html b/lib/http/testdata/Server_HandleFS/dir/index.html
new file mode 100644
index 00000000..245518a0
--- /dev/null
+++ b/lib/http/testdata/Server_HandleFS/dir/index.html
@@ -0,0 +1,6 @@
+<!doctype html>
+<html>
+ <head>
+ <title>/dir/index.html</title>
+ </head>
+</html>
diff --git a/lib/http/testdata/Server_HandleFS/index.html b/lib/http/testdata/Server_HandleFS/index.html
new file mode 100644
index 00000000..73b9ab05
--- /dev/null
+++ b/lib/http/testdata/Server_HandleFS/index.html
@@ -0,0 +1,6 @@
+<!doctype html>
+<html>
+ <head>
+ <title>/index.html</title>
+ </head>
+</html>
diff --git a/lib/http/testdata/Server_HandleFS_test.txt b/lib/http/testdata/Server_HandleFS_test.txt
index 1089121a..8b2173ef 100644
--- a/lib/http/testdata/Server_HandleFS_test.txt
+++ b/lib/http/testdata/Server_HandleFS_test.txt
@@ -1,21 +1,93 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2025 M. Shulhan <ms@kilabit.info>
-<<< TestServer_HandleFS/OnEmptyRoot
+<<< /
HTTP/1.1 200 OK
Connection: close
Content-Type: text/html; charset=utf-8
-<!DOCTYPE html><html>
-<head>
-<meta name="viewport" content="width=device-width">
-<style>
-body{font-family:monospace; white-space:pre;}
-</style>
-</head>
-<body>
-<h3>Index of /</h3>
-</body></html>
+<!doctype html>
+<html>
+ <head>
+ <title>/index.html</title>
+ </head>
+</html>
+
+<<< /dir
+HTTP/1.1 302 Found
+Connection: close
+Content-Type: text/html; charset=utf-8
+Location: /dir/
+
+<a href="/dir/">Found</a>.
+
+
+
+<<< /dir?q=abc
+HTTP/1.1 302 Found
+Connection: close
+Content-Type: text/html; charset=utf-8
+Location: /dir/?q=abc
+
+<a href="/dir/?q=abc">Found</a>.
+
+
+
+<<< /dir?q=abc#fgh
+HTTP/1.1 302 Found
+Connection: close
+Content-Type: text/html; charset=utf-8
+Location: /dir/?q=abc#fgh
+
+<a href="/dir/?q=abc#fgh">Found</a>.
+
+
+
+<<< /dir/#fgh
+HTTP/1.1 404 Not Found
+Connection: close
+
+
+
+<<< /dir/
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html; charset=utf-8
+
+<!doctype html>
+<html>
+ <head>
+ <title>/dir/index.html</title>
+ </head>
+</html>
+
+
+<<< /b
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html; charset=utf-8
+
+<!doctype html>
+<html>
+ <head>
+ <title>/b.html</title>
+ </head>
+</html>
+
+
+<<< /b?q=abc
+HTTP/1.1 200 OK
+Connection: close
+Content-Type: text/html; charset=utf-8
+
+<!doctype html>
+<html>
+ <head>
+ <title>/b.html</title>
+ </head>
+</html>
+
+
<<< TestServer_HandleFS/OnNewDirectory
HTTP/1.1 200 OK
@@ -30,6 +102,6 @@ body{font-family:monospace; white-space:pre;}
</style>
</head>
<body>
-<h3>Index of /</h3>
-<div>drwxr-xr-x <tt> 0</tt> 0000-00-00T00:00:00Z <a href="/dirA">dirA</a></div><br/>
+<h3>Index of newDir</h3>
+<div><a href='..'>..</a></div><br/>
</body></html>