~emersion/kimchi

4328cefad7beba4674ad48e103a7c9c0d9a05b2b — Simon Ser 10 months ago a00acd2
Add redirect directive
1 files changed, 14 insertions(+), 7 deletions(-)

M directives.go
M directives.go => directives.go +14 -7
@@ 104,14 104,14 @@ func parseSite(srv *Server, dir *scfg.Directive) error {
		// Then process middleware directives
		handler := backend
		for _, child := range dir.Children {
			switch child.Name {
			case "file_server", "reverse_proxy":
			if _, ok := backends[child.Name]; ok {
				// Backend directive already processed above
			default:
				handler, err = parseMiddleware(child, handler)
				if err != nil {
					return fmt.Errorf("site %q: directive %q: %v", site, child.Name, err)
				}
				continue
			}

			handler, err = parseMiddleware(child, handler)
			if err != nil {
				return fmt.Errorf("site %q: directive %q: %v", site, child.Name, err)
			}
		}



@@ 151,6 151,13 @@ var backends = map[string]parseBackendFunc{
		}
		return proxy, nil
	},
	"redirect": func(dir *scfg.Directive) (http.Handler, error) {
		var to string
		if err := dir.ParseParams(&to); err != nil {
			return nil, err
		}
		return http.RedirectHandler(to, http.StatusFound), nil
	},
}

func parseMiddleware(dir *scfg.Directive, next http.Handler) (http.Handler, error) {