Commit Graph

53 Commits

Author SHA1 Message Date
Adnan Maolood b0f27c6f74 fs: Prevent invalid directory links
A file with a name like "gemini:example" would previously result in the
following invalid link:

    => gemini:example gemini:example

Fix by prepending a "./" before each filename, so that the resulting
link looks like:

    => ./gemini:example gemini:example
2022-05-07 13:54:56 -04:00
Adnan Maolood 1170e007d4 fs: Avoid equality check if lengths don't match 2021-04-21 12:48:27 -04:00
Adnan Maolood c85759d777 fs: Improve redirect behavior 2021-04-21 12:41:56 -04:00
Adnan Maolood 507773618b fs: Refactor 2021-04-21 12:18:52 -04:00
Adnan Maolood 3bc243dd66 fs: Remove ServeContent function 2021-04-21 11:41:40 -04:00
Adnan Maolood eb32c32063 fs: Fix panic on indexing URL of zero length 2021-04-21 11:36:43 -04:00
Adnan Maolood dbbef1fb6d Revert "Require Go 1.16"
This reverts commit 0e87d64ffc.
2021-03-23 22:05:12 -04:00
Adnan Maolood a40b5dcd0b fs: Fix empty media type for directory index pages 2021-03-20 13:33:15 -04:00
Adnan Maolood 0e87d64ffc Require Go 1.16 2021-02-28 21:38:17 -05:00
Adnan Maolood cbfbeb6c22 Don't require Go 1.16 2021-02-24 14:29:29 -05:00
Adnan Maolood 6181751e8d Move mimetype registration to gemini.go 2021-02-24 14:27:49 -05:00
Adnan Maolood 25f441f573 fs: Remove build constraint 2021-02-24 11:01:02 -05:00
Adnan Maolood 15385e3095 fs: Fix Go build constraint comment 2021-02-24 09:00:28 -05:00
Kaleb Elwert 2c2d74bcb2 Only use fs.go when fs.FS is available 2021-02-24 07:41:53 -05:00
Adnan Maolood 3660698a4b Make ResponseWriter an interface
Make ResponseWriter an interface with an unexported method. Implementors
must embed a ResponseWriter from elsewhere. This gives us the
flexibility of an interface while allowing us to add new methods in the
future.
2021-02-24 00:13:46 -05:00
Adnan Maolood a65c3c3d4f Make ResponseWriter a struct
Make ResponseWriter a struct again so that it can be extended in a
backwards-compatible way.
2021-02-23 20:41:16 -05:00
Adnan Maolood 02bbedc330 Update documentation 2021-02-23 18:45:58 -05:00
Adnan Maolood 2c64db3863 Rename ResponseWriter.MediaType to SetMediaType 2021-02-21 18:52:06 -05:00
Adnan Maolood a606c4fcc0 fs: Use better error messages 2021-02-21 09:56:59 -05:00
Adnan Maolood 57e541e103 fs: Remove unused context arguments 2021-02-21 09:29:21 -05:00
Adnan Maolood e9a68917c9 handler: Make ServeGemini accept a Context 2021-02-20 15:49:14 -05:00
Adnan Maolood 110c2de6de Redesign ResponseWriter interface 2021-02-17 13:36:16 -05:00
Adnan Maolood fb9b50871c fs: Reject potentially unsafe requests in ServeFile
Reject requests where r.URL.Path contains a ".." path element to protect
against callers who might unsafely use filepath.Join on r.URL.Path
without sanitizing it.
2021-02-17 11:17:13 -05:00
Adnan Maolood 96dc161b4a fs: Add ServeContent function 2021-02-17 11:15:30 -05:00
Adnan Maolood 2e5569d5b5 fs: Fix redirect to canonical file path 2021-02-17 09:24:09 -05:00
Adnan Maolood 8eccefb8c9 fs: Add redirects 2021-02-17 01:38:18 -05:00
Adnan Maolood 995769556c fs: Trim trailing slash from name in ServeFile 2021-02-17 01:36:53 -05:00
Adnan Maolood 73bf1a31b0 fs: Clean paths before handling with FileServer 2021-02-17 00:59:15 -05:00
Adnan Maolood fa7ec1ac87 fs: Show listing for directories without index files 2021-02-17 00:08:14 -05:00
Adnan Maolood e3d1fc2785 fs: Remove leading slash before opening files 2021-02-16 23:18:37 -05:00
Adnan Maolood d2001de5f3 fs: Replace FileSystem with io/fs.FS 2021-02-16 18:53:56 -05:00
Adnan Maolood c5ccbf023a fs: Refactor 2021-02-14 19:50:38 -05:00
Adnan Maolood 5ec8dea1ba fs: Update documentation 2021-02-14 19:27:56 -05:00
Adnan Maolood f6824bd813 Make ResponseWriter an interface 2021-02-09 09:46:18 -05:00
Adnan Maolood 7910ed433b Rename Responder to Handler 2021-02-08 12:50:52 -05:00
Adnan Maolood 2b17f3d8eb fs: Remove unused import 2021-01-14 22:45:09 -05:00
Adnan Maolood af61c1b60a fs: Update comments 2021-01-14 22:27:56 -05:00
Adnan Maolood ad18ae601c fs: Don't panic on mime.AddExtensionType error
It's probably best not to panic if this fails.
2021-01-14 22:25:09 -05:00
Adnan Maolood 8473f3b9d4 fs: Update comments 2021-01-14 22:24:26 -05:00
Adnan Maolood d01d50ff1a Simplify ResponseWriter implementation 2021-01-10 00:50:35 -05:00
Hugo Wetterberg f2921a396f Add missing error handling
Error handling is currently missing is a couple of places. Most of
them are i/o related.

This change adds checks, an therefore sometimes also has to change
function signatures by adding an error return value. In the case of
the response writer the status and meta handling is changed and this
also breaks the API.

In some places where we don't have any reasonable I've added
assignment to a blank identifier to make it clear that we're ignoring
an error.

text: read the Err() that can be set by the scanner.

client: check if conn.SetDeadline() returns an error.

client: check if req.Write() returns an error.

fs: panic if mime type registration fails.

server: stop performing i/o in Header/Status functions

By deferring the actual header write to the first Write() or Flush()
call we don't have to do any error handling in Header() or Status().

As Server.respond() now defers a ResponseWriter.Flush() instead of
directly flushing the underlying bufio.Writer this has the added
benefit of ensuring that we always write a header
to the client, even if the responder is a complete NOOP.

tofu: return an error if we fail to write to the known hosts writer.
2021-01-09 23:53:07 -05:00
Adnan Maolood 85f8e84bd5 Rename (*ResponseWriter).SetMimetype to SetMediaType 2020-11-09 13:44:42 -05:00
Adnan Maolood cec1f118fb Remove some unnecessary errors 2020-11-04 23:46:05 -05:00
Adnan Maolood 34ae2a9066 Use strings.Builder in Fingerprint 2020-10-28 15:14:24 -04:00
Adnan Maolood 9079be9019 Add ServeFile function 2020-10-27 13:32:48 -04:00
Adnan Maolood 79165833de Add (*ResponseWriter).WriteStatus function 2020-10-27 13:30:35 -04:00
Adnan Maolood ca118681c0 Update documentation 2020-10-24 15:29:12 -04:00
Adnan Maolood f0345f3495 Rename repository to go-gemini 2020-10-24 15:15:32 -04:00
Adnan Maolood aeff8a051c Rename Handler to Responder 2020-10-21 16:28:50 -04:00
adnano faf94d8ba5 Rename rw, req to w, r 2020-10-13 20:22:12 -04:00