1
0
mirror of https://github.com/umputun/reproxy.git synced 2024-11-24 08:12:31 +02:00

update rest library for proper 404 content type

This commit is contained in:
Umputun 2022-01-06 01:07:50 -06:00
parent a963516783
commit e2a40bc7a6
5 changed files with 19 additions and 2 deletions

View File

@ -282,6 +282,20 @@ func TestHttp_DoWithAssetsCustom404(t *testing.T) {
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
assert.Equal(t, "not found! blah blah blah\nthere is no spoon", string(body))
t.Logf("%+v", resp.Header)
assert.Equal(t, "text/html; charset=utf-8", resp.Header.Get("Content-Type"))
}
{
resp, err := client.Get("http://localhost:" + strconv.Itoa(port) + "/static/bad2.html")
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
assert.Equal(t, "not found! blah blah blah\nthere is no spoon", string(body))
t.Logf("%+v", resp.Header)
assert.Equal(t, "text/html; charset=utf-8", resp.Header.Get("Content-Type"))
}
}

2
go.mod
View File

@ -8,7 +8,7 @@ require (
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/go-pkgz/lgr v0.10.4
github.com/go-pkgz/repeater v1.1.3
github.com/go-pkgz/rest v1.12.0
github.com/go-pkgz/rest v1.12.1
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/handlers v1.5.1
github.com/prometheus/client_golang v1.11.0

2
go.sum
View File

@ -83,6 +83,8 @@ github.com/go-pkgz/rest v1.11.0 h1:Z//qgmM0NhBYfhXYEP/aJtDVLK5XlJGxqcb4sHFNN0E=
github.com/go-pkgz/rest v1.11.0/go.mod h1:wZ/dGipZUaF9to0vIQl7PwDHgWQDB0jsrFg1xnAKLDw=
github.com/go-pkgz/rest v1.12.0 h1:zabW9ZLZzSyGsrTtEgzGUhGCfqcPnCr5nhfrap96mU4=
github.com/go-pkgz/rest v1.12.0/go.mod h1:KUWAqbDteYGS/CiXftomQsKjtEOifXsJ36Ka0skYbmk=
github.com/go-pkgz/rest v1.12.1 h1:s5EoHrHknaioHT/mGWaRMDk9GH2U/FmGMWQsCMj6III=
github.com/go-pkgz/rest v1.12.1/go.mod h1:KUWAqbDteYGS/CiXftomQsKjtEOifXsJ36Ka0skYbmk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=

View File

@ -155,6 +155,7 @@ type respWriter404 struct {
func (w *respWriter404) WriteHeader(status int) {
w.status = status
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.ResponseWriter.WriteHeader(status)
}

2
vendor/modules.txt vendored
View File

@ -26,7 +26,7 @@ github.com/go-pkgz/lgr
## explicit; go 1.12
github.com/go-pkgz/repeater
github.com/go-pkgz/repeater/strategy
# github.com/go-pkgz/rest v1.12.0
# github.com/go-pkgz/rest v1.12.1
## explicit; go 1.16
github.com/go-pkgz/rest
github.com/go-pkgz/rest/logger