diff --git a/command/serve.go b/command/serve.go index 4159a08..ed65fff 100644 --- a/command/serve.go +++ b/command/serve.go @@ -206,6 +206,33 @@ func (s serve) action(ctx context.Context, command *cli.Command) error { if err != nil { return err } + /* + requests := command.StringSlice(addRequestsFlagName) + log.Info().Msgf("%d", len(requests)) + if len(requests) > 0 { + clear(containerMethodRegex) + for _, request := range requests { + // An applicator is a container name/HTTP method pair e.g., nginx(GET). + // The following regex extracts this applicator and the associated URL regex. + aur := applicatorURLRegex.FindString(request) + if aur == "" { + // If we are here, it means that user set a wildcard (kinda) applicator e.g., GET,POST:URL_REGEX. + // In its extended form, this applicator can be read as follows: *(GET,POST):URL_REGEX. + methods, urlRegex, ok := strings.Cut(request, ":") + if !ok { // || methods == ""? + return errors.New("HTTP method(s) must be specified before ':'") + } + if err = registerMethodRegex("*", urlRegex, strings.Split(methods, ",")); err != nil { + return err + } + } + applicator, urlRegex, _ := strings.Cut(aur, ":") + if err = registerMethodRegex(containerNameRegex.FindString(applicator), urlRegex, httpMethodsRegex.FindAllString(applicator, -1)); err != nil { + return err + } + } + } + */ var l net.Listener l, err = net.Listen("tcp", ap.srvAddrPort.String()) if err != nil { @@ -417,10 +444,11 @@ func addRequests() cli.Flag { Category: "network", Usage: "add requests", Sources: middleman.PluckEnvVar(EnvVarPrefix, addRequestsFlagName), - Local: true, // Required to trigger the Action when this flag is set via the environment variable, see https://github.com/urfave/cli/issues/2041. - Value: []string{"*:" + defaultAllowedRequest}, - Aliases: middleman.PluckAlias(ServeCmd, addRequestsFlagName), + // Local: true, // Required to trigger the Action when this flag is set via the environment variable, see https://github.com/urfave/cli/issues/2041. + Value: []string{"*:" + defaultAllowedRequest}, + Aliases: middleman.PluckAlias(ServeCmd, addRequestsFlagName), Action: func(ctx context.Context, command *cli.Command, requests []string) error { + log.Info().Msgf("%d", len(requests)) clear(containerMethodRegex) for _, request := range requests { // An applicator is a container name/HTTP method pair e.g., nginx(GET).