TODO(e.burkov): Use a separate type for the YAML configuration file. createProxyConfig initializes [proxy.Config]. l must not be nil.
( ctx context.Context, l *slog.Logger, conf *configuration, )
| 35 | |
| 36 | // createProxyConfig initializes [proxy.Config]. l must not be nil. |
| 37 | func createProxyConfig( |
| 38 | ctx context.Context, |
| 39 | l *slog.Logger, |
| 40 | conf *configuration, |
| 41 | ) (proxyConf *proxy.Config, err error) { |
| 42 | hostsFiles, err := conf.hostsFiles(ctx, l) |
| 43 | if err != nil { |
| 44 | // Don't wrap the error since it's informative enough as is. |
| 45 | return nil, err |
| 46 | } |
| 47 | |
| 48 | hosts, err := middleware.ReadHosts(ctx, l, hostsFiles) |
| 49 | if err != nil { |
| 50 | return nil, fmt.Errorf("reading hosts files: %w", err) |
| 51 | } |
| 52 | |
| 53 | preMw := middleware.New(&middleware.Config{ |
| 54 | Logger: l.With(slogutil.KeyPrefix, "pre_handler_mw"), |
| 55 | // TODO(e.burkov): Use the configured message constructor. |
| 56 | MessageConstructor: dnsmsg.DefaultMessageConstructor{}, |
| 57 | HaltIPv6: conf.IPv6Disabled, |
| 58 | HostsFiles: hosts, |
| 59 | }) |
| 60 | |
| 61 | ratelimitMw, err := conf.newRatelimitMw(l) |
| 62 | if err != nil { |
| 63 | return nil, fmt.Errorf("ratelimit mw: %w", err) |
| 64 | } |
| 65 | |
| 66 | httpConf := &proxy.HTTPConfig{ |
| 67 | ServerHeader: conf.HTTPSServerName, |
| 68 | Routes: conf.DoHRoutes, |
| 69 | ReadTimeout: defaultHTTPTimeout, |
| 70 | WriteTimeout: defaultHTTPTimeout, |
| 71 | HTTP3Enabled: conf.HTTP3, |
| 72 | InsecureEnabled: conf.DoHInsecureEnabled, |
| 73 | } |
| 74 | |
| 75 | if uiStr := conf.HTTPSUserinfo; uiStr != "" { |
| 76 | user, pass, ok := strings.Cut(uiStr, ":") |
| 77 | if ok { |
| 78 | httpConf.Userinfo = url.UserPassword(user, pass) |
| 79 | } else { |
| 80 | httpConf.Userinfo = url.User(user) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | proxyConf = &proxy.Config{ |
| 85 | Logger: l.With(slogutil.KeyPrefix, proxy.LogPrefix), |
| 86 | CacheEnabled: conf.Cache, |
| 87 | CacheSizeBytes: conf.CacheSizeBytes, |
| 88 | CacheMinTTL: conf.CacheMinTTL, |
| 89 | CacheMaxTTL: conf.CacheMaxTTL, |
| 90 | CacheOptimisticAnswerTTL: time.Duration(conf.OptimisticAnswerTTL), |
| 91 | CacheOptimisticMaxAge: time.Duration(conf.OptimisticMaxAge), |
| 92 | CacheOptimistic: conf.CacheOptimistic, |
| 93 | RefuseAny: conf.RefuseAny, |
| 94 | // TODO(e.burkov): The following CIDRs are aimed to match any address. |
no test coverage detected
searching dependent graphs…