Esempio n. 1
0
// New creates and returns a ready to used ServerStatusHandler.
func New(cfg *config.Handler, loc *types.Location, next types.RequestHandler) (types.RequestHandler, error) {
	if next == nil {
		return nil, types.NilNextHandler("mp4")
	}

	// !TODO parse config
	return &mp4Handler{
		next: next,
		loc:  loc,
	}, nil
}
Esempio n. 2
0
// loggingHandler will write to accessLog each and every request to it while proxing it to next
func loggingHandler(next types.RequestHandler, accessLog io.Writer, locationIdentification string) (types.RequestHandler, error) {
	if next == nil {
		return nil, types.NilNextHandler("accessLog")
	}

	if accessLog == nil {
		return next, nil
	}

	return types.RequestHandlerFunc(
		func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
			t := time.Now()
			l := &responseLogger{ResponseWriter: w}
			url := *r.URL
			defer func() {
				go func() {
					writeLog(accessLog, r, locationIdentification, url, t, l.Status(), l.Size())
				}()
			}()
			next.RequestHandle(ctx, l, r)
		}), nil
}