Import golang/gddo at commit 20d68f94ee1f7547de2b1c68627253df20c8d45e
into daemon/server/httputils/internal/httputil.
The upstream repository was archived in 2021. Its history was filtered
to remove repository-specific CI and project files and rewritten to its
new location.
Strategy taken:
# install filter-repo (https://github.com/newren/git-filter-repo/blob/main/INSTALL.md)
brew install git-filter-repo
cd ~/projects
# create a temporary clone of gddo
git clone --single-branch --branch master --no-tags https://github.com/golang/gddo.git tmp_gddo
cd tmp_gddo
git rev-parse HEAD
20d68f94ee1f7547de2b1c68627253df20c8d45e
git filter-repo --analyze
git filter-repo \
--path httputil/negotiate.go \
--path httputil/negotiate_test.go \
--path httputil/header/header.go \
--path httputil/header/header_test.go \
--path LICENSE \
--path-rename httputil/:daemon/server/httputils/internal/httputil/ \
--path-rename LICENSE:daemon/server/httputils/internal/httputil/LICENSE \
--prune-empty always \
--prune-degenerate always
# go to the target github.com/moby/moby repository
cd ~/projects/moby
# create a branch to work with
git checkout -b import_gddo
# add the temporary repository as an upstream and make sure it's up-to-date
git remote add tmp_gddo ~/projects/tmp_gddo
git fetch --no-tags tmp_gddo master
# merge the upstream code
git merge --allow-unrelated-histories --no-ff --signoff -S tmp_gddo/master
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
22 lines
775 B
Go
22 lines
775 B
Go
// Package contentencoding provides utilities for negotiating HTTP content
|
|
// encodings.
|
|
package contentencoding
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/moby/moby/v2/daemon/server/httputils/internal/httputil"
|
|
)
|
|
|
|
// Negotiate returns the best offered content encoding for the request's
|
|
// Accept-Encoding header. If multiple offers match with equal weight, the
|
|
// offer that appears earlier in the list is preferred.
|
|
//
|
|
// It returns "identity" if no content encoding is selected and an unencoded
|
|
// response is acceptable, or an empty string if none of the offered encodings
|
|
// and identity are acceptable.
|
|
func Negotiate(requestHeaders http.Header, offers []string) string {
|
|
req := &http.Request{Header: requestHeaders}
|
|
return httputil.NegotiateContentEncoding(req, offers)
|
|
}
|