Skip to content

Commit

Permalink
docs: update documents
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Jul 5, 2022
1 parent 0a27909 commit 7d60fc8
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/http2_http3.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ curl -v --http2-prior-knowledge http://127.0.0.1:3000/

## http3

http3现在支持的浏览器只有chrome canary以及firefox最新版本,golang的http模块也未支持http3,http3的前景虽然并不确定,但是还是可以先尝尝鲜,需要注意http3还是试验性质,不要在正式环境中大规模使用。下面是使用[quic-go](https://github.com/lucas-clemente/quic-go)使用http3的示例:
http3现在支持的浏览器只有chrome canary以及firefox最新版本,虽然http3的标准方案已确定,但是需要注意http3模块的使用范围并不广泛,建议不要在正式环境中大规模使用。下面是使用[quic-go](https://github.com/lucas-clemente/quic-go)使用http3的示例:

```go
package main
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.17

require (
github.com/andybalholm/brotli v1.0.4
github.com/stretchr/testify v1.7.5
github.com/stretchr/testify v1.8.0
github.com/tidwall/gjson v1.14.1
github.com/vicanso/hes v0.6.0
github.com/vicanso/intranet-ip v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q=
github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
Expand Down
10 changes: 5 additions & 5 deletions middleware/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (cp *CacheResponse) Bytes() []byte {
func (cp *CacheResponse) GetBody(acceptEncoding string, compressor CacheCompressor) (*bytes.Buffer, string, error) {
if compressor != nil && cp.Compression == compressor.GetCompression() {
encoding := compressor.GetEncoding()
// client acccept the encoding
// client accept the encoding
if strings.Contains(acceptEncoding, encoding) {
return cp.Body, encoding, nil
}
Expand All @@ -264,7 +264,7 @@ func (cp *CacheResponse) GetBody(acceptEncoding string, compressor CacheCompress
return cp.Body, "", nil
}

// SetBody sets body to http response, it will be matched acccept-encoding
// SetBody sets body to http response, it will be matched accept-encoding
func (cp *CacheResponse) SetBody(c *elton.Context, compressor CacheCompressor) error {
// 如果body不为空
if cp.Body != nil && cp.Body.Len() != 0 {
Expand Down Expand Up @@ -308,7 +308,7 @@ func NewCacheResponse(data []byte) *CacheResponse {
hs := HTTPHeaders(data[offset : offset+size])
offset += size

commpression := data[offset]
compression := data[offset]
offset += compressionBytesSize

body := data[offset:]
Expand All @@ -318,7 +318,7 @@ func NewCacheResponse(data []byte) *CacheResponse {
CreatedAt: createdAt,
StatusCode: int(statusCode),
Header: hs.Header(),
Compression: CompressionType(commpression),
Compression: CompressionType(compression),
Body: bytes.NewBuffer(body),
}
}
Expand Down Expand Up @@ -416,7 +416,7 @@ func NewCache(config CacheConfig) elton.Handler {
if err != nil {
return err
}
compressionType := CompressionNon
compressionType := CompressionNone
if compressor != nil &&
compressor.IsValid(c.GetHeader(elton.HeaderContentType), buffer.Len()) {
// 符合压缩条件
Expand Down
6 changes: 3 additions & 3 deletions middleware/cache_compressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type CompressionType uint8

const (
// not compress
CompressionNon CompressionType = iota
CompressionNone CompressionType = iota
// gzip compress
CompressionGzip
// br compress
Expand Down Expand Up @@ -90,7 +90,7 @@ func (br *CacheBrCompressor) IsValid(contentType string, length int) bool {
func (br *CacheBrCompressor) Compress(buffer *bytes.Buffer) (*bytes.Buffer, CompressionType, error) {
data, err := BrotliCompress(buffer.Bytes(), br.Level)
if err != nil {
return nil, CompressionNon, err
return nil, CompressionNone, err
}
return data, CompressionBr, nil
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func (g *CacheGzipCompressor) IsValid(contentType string, length int) bool {
func (g *CacheGzipCompressor) Compress(buffer *bytes.Buffer) (*bytes.Buffer, CompressionType, error) {
data, err := GzipCompress(buffer.Bytes(), g.Level)
if err != nil {
return nil, CompressionNon, err
return nil, CompressionNone, err
}
return data, CompressionGzip, nil
}
Expand Down
2 changes: 1 addition & 1 deletion middleware/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestCacheResponseGetBody(t *testing.T) {
{
newRespone: func() *CacheResponse {
return &CacheResponse{
Compression: CompressionNon,
Compression: CompressionNone,
Body: bytes.NewBuffer(data),
}
},
Expand Down
2 changes: 1 addition & 1 deletion middleware/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func NewCompress(config CompressConfig) elton.Handler {

newBuf, e := compressor.Compress(body, levels...)
// 如果压缩成功,则使用压缩数据
// 失败则忽略
// 失败则忽略(不修改原数据,仅触发error)
if e != nil {
c.Elton().EmitError(c, e)
} else {
Expand Down
2 changes: 1 addition & 1 deletion middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func formatLog(c *elton.Context, tags []*LoggerTag, startedAt time.Time, default
return strings.Join(arr, "")
}

// NewLogger returns a new logger middleware, it can log the field of querystring, header, cookie and context.
// NewLogger returns a new logger middleware, it can log the field of query string, header, cookie and context.
// It will throw a panic if the Format is empty.
// It will throw a panic if the OnLog function is nil.
func NewLogger(config LoggerConfig) elton.Handler {
Expand Down

0 comments on commit 7d60fc8

Please sign in to comment.