1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-13 01:30:31 +02:00

Closes #489, Closes #781, Updated docs

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-12-20 23:00:40 -08:00
parent 562021ed2d
commit d9a6052c67
9 changed files with 24 additions and 15 deletions

View File

@ -23,7 +23,7 @@ type (
// BindUnmarshaler is the interface used to wrap the UnmarshalParam method. // BindUnmarshaler is the interface used to wrap the UnmarshalParam method.
BindUnmarshaler interface { BindUnmarshaler interface {
// UnmarshalParam decodes and assigns a value from an form or query param. // UnmarshalParam decodes and assigns a value from an form or query param.
UnmarshalParam(src string) error UnmarshalParam(param string) error
} }
) )

View File

@ -90,13 +90,17 @@ func GzipWithConfig(config GzipConfig) echo.MiddlewareFunc {
} }
} }
func (w *gzipResponseWriter) WriteHeader(code int) {
if code != http.StatusNoContent { // Issue #489
w.ResponseWriter.Header().Set(echo.HeaderContentEncoding, gzipScheme)
}
w.ResponseWriter.WriteHeader(code)
}
func (w *gzipResponseWriter) Write(b []byte) (int, error) { func (w *gzipResponseWriter) Write(b []byte) (int, error) {
if w.Header().Get(echo.HeaderContentType) == "" { if w.Header().Get(echo.HeaderContentType) == "" {
w.Header().Set(echo.HeaderContentType, http.DetectContentType(b)) w.Header().Set(echo.HeaderContentType, http.DetectContentType(b))
} }
if w.Header().Get(echo.HeaderContentEncoding) == "" {
w.Header().Set(echo.HeaderContentEncoding, gzipScheme)
}
return w.Writer.Write(b) return w.Writer.Write(b)
} }

View File

@ -27,11 +27,11 @@ func TestGzip(t *testing.T) {
// Gzip // Gzip
req, _ = http.NewRequest(echo.GET, "/", nil) req, _ = http.NewRequest(echo.GET, "/", nil)
req.Header.Set(echo.HeaderAcceptEncoding, "gzip") req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
rec = httptest.NewRecorder() rec = httptest.NewRecorder()
c = e.NewContext(req, rec) c = e.NewContext(req, rec)
h(c) h(c)
assert.Equal(t, "gzip", rec.Header().Get(echo.HeaderContentEncoding)) assert.Equal(t, gzipScheme, rec.Header().Get(echo.HeaderContentEncoding))
assert.Contains(t, rec.Header().Get(echo.HeaderContentType), echo.MIMETextPlain) assert.Contains(t, rec.Header().Get(echo.HeaderContentType), echo.MIMETextPlain)
r, err := gzip.NewReader(rec.Body) r, err := gzip.NewReader(rec.Body)
defer r.Close() defer r.Close()
@ -45,6 +45,7 @@ func TestGzip(t *testing.T) {
func TestGzipNoContent(t *testing.T) { func TestGzipNoContent(t *testing.T) {
e := echo.New() e := echo.New()
req, _ := http.NewRequest(echo.GET, "/", nil) req, _ := http.NewRequest(echo.GET, "/", nil)
req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
rec := httptest.NewRecorder() rec := httptest.NewRecorder()
c := e.NewContext(req, rec) c := e.NewContext(req, rec)
h := Gzip()(func(c echo.Context) error { h := Gzip()(func(c echo.Context) error {
@ -64,6 +65,7 @@ func TestGzipErrorReturned(t *testing.T) {
return echo.ErrNotFound return echo.ErrNotFound
}) })
req, _ := http.NewRequest(echo.GET, "/", nil) req, _ := http.NewRequest(echo.GET, "/", nil)
req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
rec := httptest.NewRecorder() rec := httptest.NewRecorder()
e.ServeHTTP(rec, req) e.ServeHTTP(rec, req)
assert.Equal(t, http.StatusNotFound, rec.Code) assert.Equal(t, http.StatusNotFound, rec.Code)

View File

@ -12,7 +12,7 @@
<h1>{{ .Site.Data.index.heading }}</h1> <h1>{{ .Site.Data.index.heading }}</h1>
<h2>{{ .Site.Data.index.description }}</h2> <h2>{{ .Site.Data.index.description }}</h2>
<p> <p>
<img style="width: 100%;" src="/images/echo_terminal.png" alt="Echo"> <img style="width: 100%;" src="/images/terminal.png" alt="Echo">
</p> </p>
</div> </div>

View File

@ -5,16 +5,18 @@
<meta http-equiv="x-ua-compatible" content="ie=edge"> <meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="{{ if ne .URL "/" }}{{ .Description }} | {{ end }}{{ .Site.Params.description }}"> <meta name="description" content="{{ if ne .URL "/" }}{{ .Description }} | {{ end }}{{ .Site.Params.description }}">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="twitter:card" content="summary"> <meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@echo"> <meta name="twitter:site" content="@echo">
<meta name="twitter:creator" content="@labstack">
<meta name="twitter:title" content="{{ if ne .URL "/" }}{{ .Title }} | {{ end }}{{ .Site.Title }}"> <meta name="twitter:title" content="{{ if ne .URL "/" }}{{ .Title }} | {{ end }}{{ .Site.Title }}">
<meta name="twitter:description" content="{{ if ne .URL "/" }}{{ .Description }} | {{ end }}{{ .Site.Params.description }}"> <meta name="twitter:description" content="{{ if ne .URL "/" }}{{ .Description }} | {{ end }}{{ .Site.Params.description }}">
<meta name="twitter:image" content="{{ .Site.BaseURL }}/images/logo.png"> <meta name="twitter:image" content="{{ .Site.BaseURL }}/images/share.png">
<meta property="og:type" content="website">
<meta property="og:site_name" content="{{ .Title }}">
<meta property="og:title" content="{{ if ne .URL "/" }}{{ .Title }} | {{ end }}{{ .Site.Title }}"> <meta property="og:title" content="{{ if ne .URL "/" }}{{ .Title }} | {{ end }}{{ .Site.Title }}">
<meta property="og:site_name" content="echo">
<meta property="og:description" content="{{ if ne .URL "/" }}{{ .Description }} | {{ end }}{{ .Site.Params.description }}"> <meta property="og:description" content="{{ if ne .URL "/" }}{{ .Description }} | {{ end }}{{ .Site.Params.description }}">
<meta property="og:url" content="{{ .Site.BaseURL }}"> <meta property="og:url" content="{{ .Site.BaseURL }}">
<meta property="og:image" content="{{ .Site.BaseURL }}/images/logo.png"> <meta property="og:image" content="{{ .Site.BaseURL }}/images/share.png">
<title> <title>
{{ if ne .URL "/" }}{{ .Title }} | {{ end }}{{ .Site.Title }} {{ if ne .URL "/" }}{{ .Title }} | {{ end }}{{ .Site.Title }}
</title> </title>

View File

@ -1,8 +1,8 @@
<!--<div class="w3-panel w3-pale-red w3-leftbar w3-border-red"> <div class="w3-panel w3-pale-green w3-leftbar w3-border-green">
<h3> <h3>
Check out our new project <a href="https://github.com/labstack/armor">Armor</a> Check out our new project <a href="https://armor.labstack.com">Armor</a>
</h3> </h3>
<p> <p>
Uncomplicated HTTP server, supports HTTP/2 and auto TLS Uncomplicated, modern HTTP server, supports HTTP/2 and auto TLS
</p> </p>
</div>--> </div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

View File

@ -0,0 +1 @@