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
Adnan Maolood
66e4dc86d5
Add optional host argument in examples/client.go
2020-10-28 16:50:17 -04:00
Adnan Maolood
b5fbd197a1
Update documentation
2020-10-28 16:02:04 -04:00
Adnan Maolood
7f0b1fa8a1
Refactor server certificates
2020-10-28 15:03:54 -04:00
Adnan Maolood
4c5167f590
Add Client.GetInput field
2020-10-27 23:35:22 -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
1634c2c11c
Add Certificate helper function
2020-10-21 17:47:34 -04:00
Adnan Maolood
ef03df7664
Refactor Input and SensitiveInput functions
2020-10-21 17:34:07 -04:00
Adnan Maolood
9506f69f1a
Refactor
2020-10-21 17:07:28 -04:00
Adnan Maolood
aeff8a051c
Rename Handler to Responder
2020-10-21 16:28:50 -04:00
Adnan Maolood
53326e59a0
Update documentation
2020-10-21 16:04:19 -04:00
Adnan Maolood
376c602748
Assume a default scheme of gemini://
2020-10-21 15:47:32 -04:00
Adnan Maolood
9daf84a121
Add support for wildcard hostnames
2020-10-21 13:22:26 -04:00
adnano
39645eb921
Rename rw to w
2020-10-13 21:00:07 -04:00
adnano
78280070ae
Add copyright notice
2020-10-13 20:36:47 -04:00
adnano
faf94d8ba5
Rename rw, req to w, r
2020-10-13 20:22:12 -04:00
adnano
4189a4f717
Move errors to gemini.go
2020-10-13 20:10:04 -04:00
adnano
92789dff19
Update comment
2020-10-13 19:11:59 -04:00
adnano
3d1e9e5519
Move certificate verification code to VerifyConnection
2020-10-13 16:44:46 -04:00
adnano
db89a34935
examples/server: Generate new certificates when they expire
2020-10-13 14:22:15 -04:00
adnano
a0aa135534
Remove (*Request).Hostname function
2020-10-13 13:31:50 -04:00
adnano
2370c42d8d
Use a map for registering server handlers
2020-10-12 16:34:12 -04:00
adnano
065ed828fb
Implement server certificate store
2020-10-11 23:48:18 -04:00
adnano
92af3df4c5
Update comments
2020-10-11 19:41:44 -04:00
adnano
7fdc28d5be
Move filesystem code to its own file
2020-10-11 18:57:04 -04:00
adnano
2d11edaa4c
Implement matching of hostnames and schemes
2020-10-11 17:53:22 -04:00
adnano
d7f515c0cb
Implement parsing of Gemini text responses
2020-09-29 10:13:57 -04:00
adnano
b557ab379b
Use path instead of filepath
2020-09-28 19:54:08 -04:00
adnano
4c0b13fb57
Refuse requests for non-gemini schemes
2020-09-28 16:07:51 -04:00
adnano
a49b0cdaac
Remove support for matching schemes
2020-09-28 16:02:32 -04:00
adnano
5a07b49ef5
Fix mux URL sorting logic
2020-09-28 15:33:15 -04:00
adnano
10760a256f
Use net/http implementation of ServeMux
2020-09-28 03:15:19 -04:00
adnano
11484b8215
Remove unused code
2020-09-28 02:17:56 -04:00
adnano
5edecf01a2
Update comments
2020-09-28 02:13:46 -04:00
adnano
b7e977f78a
Don't trim trailing slash from Handler patterns
2020-09-28 02:06:15 -04:00
adnano
70c5d8b9ce
Add WithInput helper functions
2020-09-28 02:05:37 -04:00
adnano
f09b859370
Add WithCertificate helper function
2020-09-28 01:10:36 -04:00
adnano
c3dbcb39db
Clarify comment
2020-09-27 22:13:50 -04:00
adnano
554e0af32a
Split Redirect into two functions
2020-09-27 22:06:08 -04:00
adnano
599c5bb131
Use helper functions throughout
2020-09-27 22:03:09 -04:00
adnano
707ebf1c0c
Add SetMimetype convenience function
2020-09-27 21:53:58 -04:00
adnano
5a0f7cf631
Trim trailing slash from Handler patterns
2020-09-27 21:24:08 -04:00
adnano
3c9821d812
Add more helper functions
2020-09-27 21:13:42 -04:00
adnano
fdf6bbc62f
Add helper functions
2020-09-27 20:52:24 -04:00
adnano
38fe1f21dc
Change package name to gmi
2020-09-27 20:20:59 -04:00
adnano
a4a8d49ca7
Add helper handler functions
2020-09-27 20:11:45 -04:00
adnano
a1a2523c5c
Reject requests containing '..' in them
2020-09-26 17:13:13 -04:00
adnano
92a1dbbc0c
Implement file server
2020-09-26 16:38:26 -04:00
adnano
d604e8c337
Specify minimum version of TLS 1.2
2020-09-26 00:31:16 -04:00
adnano
1f3587ba9d
Distinguish client errors from server errors
2020-09-25 23:23:24 -04:00
adnano
2f43c191cc
Reorganize
2020-09-25 19:09:49 -04:00
adnano
fdb7c9819e
Move server code to its own file
2020-09-25 19:06:56 -04:00
adnano
63696fc7c8
Refactor
2020-09-24 00:30:21 -04:00
adnano
758e056952
Handle more than one request at a time
2020-09-24 00:26:30 -04:00
adnano
6297d1e3ca
Enforce valid URLs
2020-09-21 22:21:51 -04:00
adnano
86e7fe4355
Add package declaration comment
2020-09-21 22:09:50 -04:00
adnano
01294f6661
Refactor client requests and server responses
2020-09-21 21:31:09 -04:00
adnano
5a0a515874
Provide Handler with client remote address
2020-09-21 20:44:10 -04:00
adnano
39552c0f8f
Provide Handler with client certificate information
2020-09-21 19:17:10 -04:00
adnano
cc06e65b41
Add support for client-side certificates
2020-09-21 18:21:42 -04:00
adnano
e6f70cf697
Update documentation
2020-09-21 17:36:09 -04:00
adnano
e20b8a0a5e
Add examples
2020-09-21 17:23:51 -04:00
adnano
257b807675
Initial commit
2020-09-21 15:49:09 -04:00