1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Server now use request factory

This commit is contained in:
Nan Monnand Deng 2013-08-02 03:23:46 -04:00
parent 7dac26ce69
commit 6a56b7b391
2 changed files with 15 additions and 5 deletions

View file

@ -52,9 +52,9 @@ func (v *simpleVersionInfo) Version() string {
// docker, go, git-commit (of the docker) and the host's kernel.
//
// Such information will be used on call to NewRegistry().
func (srv *Server) versionInfos() []registry.VersionInfo {
func (srv *Server) versionInfos() []utils.VersionInfo {
v := srv.DockerVersion()
ret := make([]registry.VersionInfo, 0, 4)
ret := make([]utils.VersionInfo, 0, 4)
ret = append(ret, &simpleVersionInfo{"docker", v.Version})
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) {
r, err := registry.NewRegistry(srv.runtime.root, nil, srv.versionInfos()...)
r, err := registry.NewRegistry(srv.runtime.root, nil, srv.reqFactory)
if err != nil {
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 {
r, err := registry.NewRegistry(srv.runtime.root, authConfig, srv.versionInfos()...)
r, err := registry.NewRegistry(srv.runtime.root, authConfig, srv.reqFactory)
if err != nil {
return err
}
@ -720,7 +720,7 @@ func (srv *Server) ImagePush(localName string, out io.Writer, sf *utils.StreamFo
out = utils.NewWriteFlusher(out)
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 {
return err2
}
@ -1164,7 +1164,11 @@ func NewServer(flGraphPath string, autoRestart, enableCors bool, dns ListOpts) (
pushingPool: make(map[string]struct{}),
events: make([]utils.JSONMessage, 0, 64), //only keeps the 64 last events
listeners: make(map[string]chan utils.JSONMessage),
reqFactory: nil,
}
ud := utils.NewHTTPUserAgentDecorator(srv.versionInfos()...)
factory := utils.NewHTTPRequestFactory(ud)
srv.reqFactory = factory
runtime.srv = srv
return srv, nil
}
@ -1189,4 +1193,5 @@ type Server struct {
pushingPool map[string]struct{}
events []utils.JSONMessage
listeners map[string]chan utils.JSONMessage
reqFactory *utils.HTTPRequestFactory
}

View file

@ -113,6 +113,11 @@ func (self *HTTPRequestFactory) NewRequest(method, urlStr string, body io.Reader
if err != nil {
return nil, err
}
// By default, a nil factory should work.
if self == nil {
return req, nil
}
for _, dec := range self.decorators {
req, err = dec.ChangeRequest(req)
if err != nil {