MCPcopy
hub / github.com/perkeep/perkeep / fixServerInConfig

Function fixServerInConfig

pkg/server/help.go:90–110  ·  view source on GitHub ↗

fixServerInConfig checks if cc contains a meaningful server (for a client). If not, a newly allocated clone of cc is returned, except req.Host is used for the hostname of the server. Otherwise, cc is returned.

(cc *clientconfig.Config, req *http.Request)

Source from the content-addressed store, hash-verified

88// If not, a newly allocated clone of cc is returned, except req.Host is used for
89// the hostname of the server. Otherwise, cc is returned.
90func fixServerInConfig(cc *clientconfig.Config, req *http.Request) (*clientconfig.Config, error) {
91 if cc == nil {
92 return nil, errors.New("nil client config")
93 }
94 if len(cc.Servers) == 0 || cc.Servers["default"] == nil || cc.Servers["default"].Server == "" {
95 return nil, errors.New("no Server in client config")
96 }
97 listen := strings.TrimPrefix(strings.TrimPrefix(cc.Servers["default"].Server, "http://"), "https://")
98 if !(strings.HasPrefix(listen, "0.0.0.0") || strings.HasPrefix(listen, ":")) {
99 return cc, nil
100 }
101 newCC := *cc
102 server := newCC.Servers["default"]
103 if req.TLS != nil {
104 server.Server = "https://" + req.Host
105 } else {
106 server.Server = "http://" + req.Host
107 }
108 newCC.Servers["default"] = server
109 return &newCC, nil
110}
111
112func (hh *HelpHandler) InitHandler(hl blobserver.FindHandlerByTyper) error {
113 if hh.serverConfig == nil {

Callers 1

ServeHTTPMethod · 0.85

Calls 1

HasPrefixMethod · 0.80

Tested by

no test coverage detected