httpfactory.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package registry
  2. import (
  3. "runtime"
  4. "github.com/docker/docker/dockerversion"
  5. "github.com/docker/docker/pkg/parsers/kernel"
  6. "github.com/docker/docker/utils"
  7. )
  8. func HTTPRequestFactory(metaHeaders map[string][]string) *utils.HTTPRequestFactory {
  9. // FIXME: this replicates the 'info' job.
  10. httpVersion := make([]utils.VersionInfo, 0, 4)
  11. httpVersion = append(httpVersion, &simpleVersionInfo{"docker", dockerversion.VERSION})
  12. httpVersion = append(httpVersion, &simpleVersionInfo{"go", runtime.Version()})
  13. httpVersion = append(httpVersion, &simpleVersionInfo{"git-commit", dockerversion.GITCOMMIT})
  14. if kernelVersion, err := kernel.GetKernelVersion(); err == nil {
  15. httpVersion = append(httpVersion, &simpleVersionInfo{"kernel", kernelVersion.String()})
  16. }
  17. httpVersion = append(httpVersion, &simpleVersionInfo{"os", runtime.GOOS})
  18. httpVersion = append(httpVersion, &simpleVersionInfo{"arch", runtime.GOARCH})
  19. ud := utils.NewHTTPUserAgentDecorator(httpVersion...)
  20. md := &utils.HTTPMetaHeadersDecorator{
  21. Headers: metaHeaders,
  22. }
  23. factory := utils.NewHTTPRequestFactory(ud, md)
  24. return factory
  25. }
  26. // simpleVersionInfo is a simple implementation of
  27. // the interface VersionInfo, which is used
  28. // to provide version information for some product,
  29. // component, etc. It stores the product name and the version
  30. // in string and returns them on calls to Name() and Version().
  31. type simpleVersionInfo struct {
  32. name string
  33. version string
  34. }
  35. func (v *simpleVersionInfo) Name() string {
  36. return v.name
  37. }
  38. func (v *simpleVersionInfo) Version() string {
  39. return v.version
  40. }