Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding gzip compression for HTTP and Headers for tracker's sec #181

Merged
merged 1 commit into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FATHOM_GZIP=true
FATHOM_DEBUG=true
FATHOM_DATABASE_DRIVER="sqlite3"
FATHOM_DATABASE_NAME="./fathom.db"
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
- "8080:8080"
environment:
- "FATHOM_SERVER_ADDR=:8080"
- "FATHOM_GZIP=true"
- "FATHOM_DEBUG=false"
- "FATHOM_DATABASE_DRIVER=mysql"
- "FATHOM_DATABASE_NAME=fathom"
Expand Down
2 changes: 2 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fathom --config=/home/john/fathom.env server
The default configuration looks like this:

```
FATHOM_GZIP=true
FATHOM_DEBUG=true
FATHOM_DATABASE_DRIVER="sqlite3"
FATHOM_DATABASE_NAME="./fathom.db"
Expand All @@ -29,6 +30,7 @@ FATHOM_SECRET="random-secret-string"
| :---- | :---| :---
| FATHOM_DEBUG | `false` | If `true` will write more log messages.
| FATHOM_SERVER_ADDR | `:8080` | The server address to listen on
| FATHOM_GZIP | `false` | if `true` will HTTP content gzipped
| FATHOM_DATABASE_DRIVER | `sqlite3` | The database driver to use: `mysql`, `postgres` or `sqlite3`
| FATHOM_DATABASE_NAME | | The name of the database to connect to (or path to database file if using sqlite3)
| FATHOM_DATABASE_USER | | Database connection user
Expand Down
1 change: 1 addition & 0 deletions docs/Installation instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Then, create a file named `.env` with the following contents.

```
FATHOM_SERVER_ADDR=9000
FATHOM_GZIP=true
FATHOM_DEBUG=true
FATHOM_DATABASE_DRIVER="sqlite3"
FATHOM_DATABASE_NAME="fathom.db"
Expand Down
5 changes: 5 additions & 0 deletions pkg/api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func serveFile(box *packr.Box, filename string) Handler {
return err
}

// setting security and cache headers
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("X-Xss-Protection", "1; mode=block")
w.Header().Set("Cache-Control", "max-age=432000") // 5 days

http.ServeContent(w, r, filename, d.ModTime(), f)
return nil
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ var serverCmd = cli.Command{
Name: "lets-encrypt",
},

cli.BoolFlag{
EnvVar: "FATHOM_GZIP",
Name: "gzip",
Usage: "enable gzip compression",
},

cli.StringFlag{
EnvVar: "FATHOM_HOSTNAME",
Name: "hostname",
Expand All @@ -57,6 +63,11 @@ func server(c *cli.Context) error {
log.SetLevel(log.WarnLevel)
}

// set gzip compression if --gzip was passed
if c.Bool("gzip") {
h = handlers.CompressHandler(h)
}

// if addr looks like a number, prefix with :
addr := c.String("addr")
if _, err := strconv.Atoi(addr); err == nil {
Expand Down