Commit Graph

114 Commits

Author SHA1 Message Date
Adnan Maolood
a7f958b20d server: Make Request.RemoteAddr a string 2021-02-20 13:31:55 -05:00
Adnan Maolood
64dbb3eecb server: Clarify GetCertificate documentation 2021-02-19 18:53:06 -05:00
Adnan Maolood
2e149c9ccd server: Remove Certificates field
Use GetCertificate to retrieve certificates without consulting
Certificates.
2021-02-18 22:22:20 -05:00
Adnan Maolood
6edde376c4 server: Add Handler field and remove Handle methods 2021-02-17 20:31:03 -05:00
Adnan Maolood
b5a3c0adc5 Add utility Handler functions 2021-02-17 19:27:25 -05:00
Adnan Maolood
110c2de6de Redesign ResponseWriter interface 2021-02-17 13:36:16 -05:00
Adnan Maolood
a3c1804395 Move ResponseWriter.Flush to Flusher interface 2021-02-17 11:44:13 -05:00
Adnan Maolood
1d6cbddc5b server: Prevent adding Listeners after Close
Check done after calling trackListener to prevent the listener from
being registered after the server is closed.
2021-02-15 20:19:44 -05:00
Adnan Maolood
a05fa6d6bd server: Avoid creating a new Listener after Close 2021-02-15 20:16:32 -05:00
Adnan Maolood
f158bb5f1d server: Use separate mutex for handlers 2021-02-15 20:05:47 -05:00
Adnan Maolood
5a784693ef server: Rename responder to handler 2021-02-15 01:15:23 -05:00
Adnan Maolood
2c7f8273e9 server: Recover from ServeGemini panics 2021-02-15 00:36:33 -05:00
Adnan Maolood
3f2d540579 server: Implement Close and Shutdown methods 2021-02-14 23:58:33 -05:00
Adnan Maolood
6f7c183662 server: Don't populate Request.Certificate field
Handlers should instead use the certificate provided in Request.TLS.
2021-02-14 17:34:57 -05:00
Adnan Maolood
7c703e95de Update documentation 2021-02-14 15:50:41 -05:00
Adnan Maolood
595b0d0490 server: Populate Request.RemoteAddr field 2021-02-13 21:10:19 -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
29f2b3738d Make TLS field nil for unencrypted connections 2021-02-08 12:32:49 -05:00
Adnan Maolood
9e89b93bab server: Allow handling any hostname with "*"
Allow registering a responder with the special pattern "*" to handle any
hostname.
2021-01-25 10:55:40 -05:00
Adnan Maolood
06c53cc5b1 server: Rename Register to Handle 2021-01-14 22:12:07 -05:00
Adnan Maolood
14d89f304a Move cert.go to a subpackage 2021-01-14 20:42:12 -05:00
Adnan Maolood
d01d50ff1a Simplify ResponseWriter implementation 2021-01-10 00:50:35 -05:00
Adnan Maolood
3ed39e62d8 Rename status.Message to status.Meta 2021-01-10 00:10:57 -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
Hugo Wetterberg
efef44c2f9 server: abort request handling on bad requests
A request to a hostname that hasn't been registered with the server
currently results in a nil pointer deref panic in server.go:215 as
request handling continues even if ReadRequest() returns an error.

This change changes all if-else error handling in Server.respond() to
a WriteStatus-call and early return. This makes it clear when request
handling is aborted (and actually aborts when ReadRequest() fails).
2021-01-05 18:33:36 -05:00
Adnan Maolood
61b417a5c4 Add ResponseWriter.Flush function 2020-12-18 13:15:34 -05:00
Adnan Maolood
d9a690a98f Make NewResponseWriter take an io.Writer 2020-12-18 01:47:29 -05:00
Adnan Maolood
d34d5df89e Add ReadRequest and ReadResponse functions 2020-12-18 01:42:05 -05:00
Adnan Maolood
decd72cc23 Expose Request.Write and Response.Read functions 2020-12-18 01:14:06 -05:00
Adnan Maolood
c329a2487e server: Don't always assume TLS is used 2020-12-18 01:02:04 -05:00
Adnan Maolood
35836f2ff7 Remove Input function 2020-12-18 00:25:06 -05:00
Adnan Maolood
cab23032c0 Don't assume a default scheme of gemini 2020-11-24 17:13:52 -05:00
Adnan Maolood
0c75e5d5ad Expose KnownHosts and CertificateStore internals 2020-11-23 12:17:54 -05:00
Adnan Maolood
3dee6dcff3 Add (*CertificateStore).Write function 2020-11-09 13:54:15 -05:00
Adnan Maolood
85f8e84bd5 Rename (*ResponseWriter).SetMimetype to SetMediaType 2020-11-09 13:44:42 -05:00
Adnan Maolood
ff6c95930b Fix TOFU 2020-11-05 22:30:13 -05:00
Adnan Maolood
b76080c863 Refactor KnownHosts 2020-11-05 15:27:12 -05:00
Adnan Maolood
610c6fc533 Add ErrorLog field to Server 2020-11-03 16:11:31 -05:00
Adnan Maolood
b6475aa7d9 server: Populate (*Request).Certificate field 2020-11-01 16:25:59 -05:00
adnano
e4dea6f2c8 Refactor Certificate and Input functions 2020-11-01 14:35:03 -05:00
Adnan Maolood
7fb1b6c6a4 Update documentation 2020-11-01 00:10:30 -04:00
Adnan Maolood
65a5065250 Refactor client.TrustCertificate workflow 2020-10-31 22:34:51 -04:00
Adnan Maolood
7d470c5fb1 Implement Server read and write timeouts 2020-10-31 21:07:02 -04:00
Adnan Maolood
a2fc1772bf Set default mimetype if META is empty 2020-10-31 20:32:38 -04:00
Adnan Maolood
63b9b484d1 Remove Redirect and PermanentRedirect functions
Use (*ResponseWriter).WriteHeader instead.
2020-10-31 16:51:10 -04:00
Adnan Maolood
ca8e0166fc Add ErrCertificateNotFound 2020-10-31 16:45:38 -04:00
Adnan Maolood
14ef3be6fe server: Automatically write new certificates to disk 2020-10-31 16:33:56 -04:00
Adnan Maolood
3aa254870a Call CreateCertificate for missing certificates 2020-10-31 15:38:39 -04:00
Adnan Maolood
a89065babb Fix handling of wildcard hostnames 2020-10-31 15:11:05 -04:00