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)
| 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. |
| 90 | func 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 | |
| 112 | func (hh *HelpHandler) InitHandler(hl blobserver.FindHandlerByTyper) error { |
| 113 | if hh.serverConfig == nil { |