mirror of
https://github.com/minio/minio.git
synced 2026-02-07 11:20:16 -05:00
- over the course of a project history every maintainer needs to update
its dependency packages, the problem essentially with godep is manipulating
GOPATH - this manipulation leads to static objects created at different locations
which end up conflicting with the overall functionality of golang.
This also leads to broken builds. There is no easier way out of this other than
asking developers to do 'godep restore' all the time. Which perhaps as a practice
doesn't sound like a clean solution. On the other hand 'godep restore' has its own
set of problems.
- govendor is a right tool but a stop gap tool until we wait for golangs official
1.5 version which fixes this vendoring issue once and for all.
- govendor provides consistency in terms of how import paths should be handled unlike
manipulation GOPATH.
This has advantages
- no more compiled objects being referenced in GOPATH and build time GOPATH
manging which leads to conflicts.
- proper import paths referencing the exact package a project is dependent on.
govendor is simple and provides the minimal necessary tooling to achieve this.
For now this is the right solution.
91 lines
2.1 KiB
Go
91 lines
2.1 KiB
Go
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Copyright 2012 The Gorilla Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package rpc
|
|
|
|
import (
|
|
"compress/flate"
|
|
"compress/gzip"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
// gzipWriter writes and closes the gzip writer.
|
|
type gzipWriter struct {
|
|
w *gzip.Writer
|
|
}
|
|
|
|
func (gw *gzipWriter) Write(p []byte) (n int, err error) {
|
|
defer gw.w.Close()
|
|
return gw.w.Write(p)
|
|
}
|
|
|
|
// gzipEncoder implements the gzip compressed http encoder.
|
|
type gzipEncoder struct {
|
|
}
|
|
|
|
func (enc *gzipEncoder) Encode(w http.ResponseWriter) io.Writer {
|
|
w.Header().Set("Content-Encoding", "gzip")
|
|
return &gzipWriter{gzip.NewWriter(w)}
|
|
}
|
|
|
|
// flateWriter writes and closes the flate writer.
|
|
type flateWriter struct {
|
|
w *flate.Writer
|
|
}
|
|
|
|
func (fw *flateWriter) Write(p []byte) (n int, err error) {
|
|
defer fw.w.Close()
|
|
return fw.w.Write(p)
|
|
}
|
|
|
|
// flateEncoder implements the flate compressed http encoder.
|
|
type flateEncoder struct {
|
|
}
|
|
|
|
func (enc *flateEncoder) Encode(w http.ResponseWriter) io.Writer {
|
|
fw, err := flate.NewWriter(w, flate.DefaultCompression)
|
|
if err != nil {
|
|
return w
|
|
}
|
|
w.Header().Set("Content-Encoding", "deflate")
|
|
return &flateWriter{fw}
|
|
}
|
|
|
|
// CompressionSelector generates the compressed http encoder.
|
|
type CompressionSelector struct {
|
|
}
|
|
|
|
// acceptedEnc returns the first compression type in "Accept-Encoding" header
|
|
// field of the request.
|
|
func acceptedEnc(req *http.Request) string {
|
|
encHeader := req.Header.Get("Accept-Encoding")
|
|
if encHeader == "" {
|
|
return ""
|
|
}
|
|
encTypes := strings.FieldsFunc(encHeader, func(r rune) bool {
|
|
return unicode.IsSpace(r) || r == ','
|
|
})
|
|
for _, enc := range encTypes {
|
|
if enc == "gzip" || enc == "deflate" {
|
|
return enc
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// Select method selects the correct compression encoder based on http HEADER.
|
|
func (_ *CompressionSelector) Select(r *http.Request) Encoder {
|
|
switch acceptedEnc(r) {
|
|
case "gzip":
|
|
return &gzipEncoder{}
|
|
case "flate":
|
|
return &flateEncoder{}
|
|
}
|
|
return DefaultEncoder
|
|
}
|