// New creates and returns a ready to used ServerStatusHandler. func New(cfg *config.Handler, l *types.Location, next types.RequestHandler) (types.RequestHandler, error) { return types.RequestHandlerFunc( func(ctx context.Context, w http.ResponseWriter, r *http.Request) { var start, err = strconv.Atoi(r.URL.Query().Get(startKey)) if err != nil || 0 >= start { // pass next.RequestHandle(ctx, w, r) return } r.URL.Query().Del(startKey) // clean that r.Header.Add("Range", fmt.Sprintf("bytes=%d-", start)) next.RequestHandle(ctx, &flvWriter{w: w}, r) }), nil }
// New creates and returns a ready to used ServerStatusHandler. func New(cfg *config.Handler, l *types.Location, next types.RequestHandler) (types.RequestHandler, error) { var s struct { Speed types.BytesSize `json:"speed"` } if err := json.Unmarshal(cfg.Settings, &s); err != nil { return nil, fmt.Errorf("handler.throttle got error while parsing settings - %s", err) } if s.Speed == 0 { return nil, fmt.Errorf("handler.throttle needs to have speed settings > 0") } return types.RequestHandlerFunc( func(ctx context.Context, w http.ResponseWriter, r *http.Request) { next.RequestHandle(ctx, &throttledResponseWriter{ResponseWriter: w, ThrottlerWriter: iocontrol.ThrottledWriter(w, int(s.Speed.Bytes()), time.Millisecond*10), }, r) }), nil }
// 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 }