Browse Source

Return 'Not found' on stat error

master
Trevor Slocum 2 years ago
parent
commit
b4876f8756
  1. 9
      CONFIGURATION.md
  2. 5
      README.md
  3. 7
      server.go

9
CONFIGURATION.md

@ -1,7 +1,6 @@
`twins` requires a configuration file to operate. By default, it is loaded from
`~/.config/twins/config.yaml`. You may specify a different location via the
`--config` argument.
`twins` requires a configuration file to operate. It is loaded from
`~/.config/twins/config.yaml` by default. You may specify a different location
via the `--config` argument.
# Configuration options
@ -140,4 +139,4 @@ hosts:
-
path: /
root: /home/twins/data/home
```
```

5
README.md

@ -10,7 +10,7 @@ Breaking changes may be made.
## Features
- Serve static files
- Directory listing may be enabled
- Directory listing (when enabled)
- Serve the output of system commands
- Reverse proxy requests
@ -37,3 +37,6 @@ Please share issues and suggestions [here](https://gitlab.com/tslocum/twins/issu
## Dependencies
- [go-gemini](https://github.com/makeworld-the-better-one/go-gemini)
- [go-shellquote](https://github.com/kballard/go-shellquote)
- [filetype](https://github.com/h2non/filetype)
- [yaml](https://github.com/go-yaml/yaml/tree/v3)

7
server.go

@ -140,12 +140,9 @@ func serveDirectory(c net.Conn, request *url.URL, dirPath string) {
func serveFile(c net.Conn, request *url.URL, requestData, filePath string, listDir bool) {
fi, err := os.Stat(filePath)
if os.IsNotExist(err) {
if err != nil {
writeStatus(c, gemini.StatusNotFound)
return
} else if err != nil {
writeStatus(c, gemini.StatusTemporaryFailure)
return
}
originalPath := filePath
@ -329,7 +326,7 @@ func handleConn(c net.Conn) {
log.Printf("> %s\n", requestData)
}
if len(requestData) > 1024 || !utf8.ValidString(requestData) {
if len(requestData) > gemini.URLMaxLength || !utf8.ValidString(requestData) {
writeStatus(c, gemini.StatusBadRequest)
return
}

Loading…
Cancel
Save