Skip to content

Commit 8b9b1d6

Browse files
committed
ed
1 parent 9ca1134 commit 8b9b1d6

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# httpfileserver
22

3-
[![travis](https://travis-ci.org/schollz/httpfileserver.svg?branch=master)](https://travis-ci.org/schollz/httpfileserver)
4-
[![go report card](https://goreportcard.com/badge/github.com/schollz/httpfileserver)](https://goreportcard.com/report/github.com/schollz/httpfileserver)
5-
[![coverage](https://img.shields.io/badge/coverage-90%25-brightgreen.svg)](https://gocover.io/github.com/schollz/httpfileserver)
6-
[![godocs](https://godoc.org/github.com/schollz/httpfileserver?status.svg)](https://godoc.org/github.com/schollz/httpfileserver)
3+
[![go report card](https://goreportcard.com/badge/github.com/3JoB/httpfileserver)](https://goreportcard.com/report/github.com/3JoB/httpfileserver)
4+
[![godocs](https://godoc.org/github.com/3JoB/httpfileserver?status.svg)](https://godoc.org/github.com/3JoB/httpfileserver)
5+
6+
7+
Fork from https://github.com/schollz/httpfileserver . This branch supports deflate, brotli, gzip and other methods.
8+
79

810

911
This is a drop-in replacement for the stdlib `http.FileServer` that automatically provides gzipping as well as serving from memory instead of from disk. This library wraps the stdlib `http.FileServer` so you get all the benefits of that code, while also providing gzipping and keeping track of bytes and storing served files from memory when they come available.
@@ -18,6 +20,10 @@ with this version
1820

1921
## Usage
2022

23+
```
24+
go get -u github.com/3JoB/httpfileserver
25+
```
26+
2127
In order to serve files from a different directory other than specified by the route, you need to include the route when specifying a file server. For example, if you want to serve `/static` files from a local directory called `/tmp/myassets` then you can specify a new file server in the following:
2228

2329
http.Handle("/static/", httpfileserver.New("/static/", "/tmp/myassets"))
@@ -33,11 +39,14 @@ package main
3339
import (
3440
"net/http"
3541

36-
"github.com/schollz/httpfileserver"
42+
"github.com/3JoB/httpfileserver"
3743
)
3844

3945
func main() {
4046
// Any request to /static/somefile.txt will serve the file at the location ./somefile.txt
47+
var fsr httpfileserver.FileServer
48+
fsr.Config.FlateLevel = 3
49+
4150
http.HandleFunc("/static/", httpfileserver.New("/static/", ".").Handle())
4251
http.ListenAndServe(":1113", nil)
4352
}

httpfileserver_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package httpfileserver
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"net/http/httptest"
88
"testing"
@@ -27,6 +27,7 @@ func BenchmarkServerDisableCache(b *testing.B) {
2727
resp.Body.Close()
2828
}
2929
}
30+
3031
func BenchmarkServerMaxBytes(b *testing.B) {
3132
ts := httptest.NewServer(New("/", ".", OptionMaxBytes(10)).Handle())
3233
defer ts.Close()
@@ -46,12 +47,11 @@ func TestServer(t *testing.T) {
4647
if err != nil {
4748
t.Errorf("%s", err)
4849
}
49-
greeting, _ := ioutil.ReadAll(res.Body)
50+
greeting, _ := io.ReadAll(res.Body)
5051
res.Body.Close()
5152

5253
fmt.Printf("%s", greeting)
5354
}
54-
5555
}
5656

5757
func TestServerMaxBytes(t *testing.T) {
@@ -63,10 +63,9 @@ func TestServerMaxBytes(t *testing.T) {
6363
if err != nil {
6464
t.Errorf("%s", err)
6565
}
66-
greeting, _ := ioutil.ReadAll(res.Body)
66+
greeting, _ := io.ReadAll(res.Body)
6767
res.Body.Close()
6868

6969
fmt.Printf("%s", greeting)
7070
}
71-
7271
}

0 commit comments

Comments
 (0)