Skip to content

Commit 9b71c3d

Browse files
committed
add titan documentation to README
1 parent 3e5d9a0 commit 9b71c3d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ API is subject to change until v1.0
4040
* [Custom port](#custom-port)
4141
* [Custom TLS config](#custom-tls-config)
4242
* [Testing](#testing)
43+
* [Titan protocol](#titan-protocol)
4344
* [Who uses Gig](#who-uses-gig)
4445
* [Benchmarks](#benchmarks)
4546
* [Contribute](#contribute)
@@ -530,6 +531,56 @@ func TestCertificate(t *testing.T) {
530531
}
531532
```
532533

534+
### Titan Protocol
535+
536+
[Titan] protocol is supported as middleware. Example titan server can be found
537+
in `examples/titan` directory.
538+
539+
To use handle titan requests you must set `AllowProxying` property of gig to true.
540+
541+
```go
542+
g := gig.Default()
543+
g.AllowProxying = true
544+
```
545+
546+
It is recommenced to set request read timeout to non zero value:
547+
548+
```go
549+
g.ReadTimeout = time.Second * 10
550+
```
551+
552+
When creating middleware you must provide maximal request size in
553+
bytes. Attempt to send bigger files than the limit will result in bad
554+
request response.
555+
556+
```go
557+
g.Use(gig.Titan(1024))
558+
```
559+
560+
Titan middleware detects requests using `titan://` scheme and stores information about
561+
it in request's context.
562+
563+
| key | type | description |
564+
|-------|--------|-----------------------------------------|
565+
| titan | bool | true if request is titan request |
566+
| size | int | size of received file |
567+
| mime | string | mime type as described in [Titan] spec |
568+
| token | string | auth token as described in [Titan] spec |
569+
570+
The `titan` key in a context can be used to implement handlers that can
571+
handle both titan and gemini requests.
572+
573+
Please note that if client sends less data than indicated by size parameter
574+
then request should result in error response.
575+
576+
There are two utility function provided to make writing Titan servers easier:
577+
578+
- `TitanReadFull`: reads whole request into a buffer. Takes care of case
579+
when client sends less data than expeted.
580+
- `TitanRedirect`: redirects client to the gemini resource uploaded in the request.
581+
582+
[Titan]: https://communitywiki.org/wiki/Titan
583+
533584
## Who uses Gig
534585

535586
Gig is used by the following capsules:

0 commit comments

Comments
 (0)