mirror of https://github.com/docker/docs.git
Server now use request factory
This commit is contained in:
parent
7dac26ce69
commit
6a56b7b391
15
server.go
15
server.go
|
@ -52,9 +52,9 @@ func (v *simpleVersionInfo) Version() string {
|
||||||
// docker, go, git-commit (of the docker) and the host's kernel.
|
// docker, go, git-commit (of the docker) and the host's kernel.
|
||||||
//
|
//
|
||||||
// Such information will be used on call to NewRegistry().
|
// Such information will be used on call to NewRegistry().
|
||||||
func (srv *Server) versionInfos() []registry.VersionInfo {
|
func (srv *Server) versionInfos() []utils.VersionInfo {
|
||||||
v := srv.DockerVersion()
|
v := srv.DockerVersion()
|
||||||
ret := make([]registry.VersionInfo, 0, 4)
|
ret := make([]utils.VersionInfo, 0, 4)
|
||||||
ret = append(ret, &simpleVersionInfo{"docker", v.Version})
|
ret = append(ret, &simpleVersionInfo{"docker", v.Version})
|
||||||
|
|
||||||
if len(v.GoVersion) > 0 {
|
if len(v.GoVersion) > 0 {
|
||||||
|
@ -102,7 +102,7 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ImagesSearch(term string) ([]APISearch, error) {
|
func (srv *Server) ImagesSearch(term string) ([]APISearch, error) {
|
||||||
r, err := registry.NewRegistry(srv.runtime.root, nil, srv.versionInfos()...)
|
r, err := registry.NewRegistry(srv.runtime.root, nil, srv.reqFactory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -559,7 +559,7 @@ func (srv *Server) poolRemove(kind, key string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig) error {
|
func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig) error {
|
||||||
r, err := registry.NewRegistry(srv.runtime.root, authConfig, srv.versionInfos()...)
|
r, err := registry.NewRegistry(srv.runtime.root, authConfig, srv.reqFactory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -720,7 +720,7 @@ func (srv *Server) ImagePush(localName string, out io.Writer, sf *utils.StreamFo
|
||||||
|
|
||||||
out = utils.NewWriteFlusher(out)
|
out = utils.NewWriteFlusher(out)
|
||||||
img, err := srv.runtime.graph.Get(localName)
|
img, err := srv.runtime.graph.Get(localName)
|
||||||
r, err2 := registry.NewRegistry(srv.runtime.root, authConfig, srv.versionInfos()...)
|
r, err2 := registry.NewRegistry(srv.runtime.root, authConfig, srv.reqFactory)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return err2
|
return err2
|
||||||
}
|
}
|
||||||
|
@ -1164,7 +1164,11 @@ func NewServer(flGraphPath string, autoRestart, enableCors bool, dns ListOpts) (
|
||||||
pushingPool: make(map[string]struct{}),
|
pushingPool: make(map[string]struct{}),
|
||||||
events: make([]utils.JSONMessage, 0, 64), //only keeps the 64 last events
|
events: make([]utils.JSONMessage, 0, 64), //only keeps the 64 last events
|
||||||
listeners: make(map[string]chan utils.JSONMessage),
|
listeners: make(map[string]chan utils.JSONMessage),
|
||||||
|
reqFactory: nil,
|
||||||
}
|
}
|
||||||
|
ud := utils.NewHTTPUserAgentDecorator(srv.versionInfos()...)
|
||||||
|
factory := utils.NewHTTPRequestFactory(ud)
|
||||||
|
srv.reqFactory = factory
|
||||||
runtime.srv = srv
|
runtime.srv = srv
|
||||||
return srv, nil
|
return srv, nil
|
||||||
}
|
}
|
||||||
|
@ -1189,4 +1193,5 @@ type Server struct {
|
||||||
pushingPool map[string]struct{}
|
pushingPool map[string]struct{}
|
||||||
events []utils.JSONMessage
|
events []utils.JSONMessage
|
||||||
listeners map[string]chan utils.JSONMessage
|
listeners map[string]chan utils.JSONMessage
|
||||||
|
reqFactory *utils.HTTPRequestFactory
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,6 +113,11 @@ func (self *HTTPRequestFactory) NewRequest(method, urlStr string, body io.Reader
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// By default, a nil factory should work.
|
||||||
|
if self == nil {
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
for _, dec := range self.decorators {
|
for _, dec := range self.decorators {
|
||||||
req, err = dec.ChangeRequest(req)
|
req, err = dec.ChangeRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue