Return 'Not found' on stat error

This commit is contained in:
Trevor Slocum 2020-10-31 09:59:12 -07:00
parent 8465ad9871
commit b4876f8756
3 changed files with 10 additions and 11 deletions

View file

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

View file

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

View file

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