Esempio n. 1
0
File: server.go Progetto: htee/htee
func (s *server) recordStream(ctx context.Context, res http.ResponseWriter, req *http.Request) {
	name := req.URL.Path

	conn, hw, _ := res.(http.Hijacker).Hijack()
	defer conn.Close()

	if err := writeContinue(hw, name); err != nil {
		s.handleError(res, req, err)
		return
	}

	in := stream.In(ctx, name, req.Body)

	select {
	case <-in.Done():
		if in.Err != nil {
			s.handleError(res, req, in.Err)
		} else {
			if err := writeNoContent(hw); err != nil {
				s.handleError(res, req, err)
			}
		}
	case <-res.(http.CloseNotifier).CloseNotify():
		in.Cancel()
	}
}
Esempio n. 2
0
File: server.go Progetto: htee/hteed
func (s *server) recordStream(ctx context.Context, res http.ResponseWriter, req *http.Request) {
	name := req.URL.Path

	conn, hw, err := res.(http.Hijacker).Hijack()
	if err != nil {
		s.handleError(res, req, err)
		return
	}

	defer conn.Close()
	defer s.closeHijacked(conn)

	if err := writeContinue(hw, name); err != nil {
		s.handleError(res, req, err)
		return
	}

	reader := &io.LimitedReader{R: req.Body, N: 1 << 20}
	in := stream.In(ctx, name, reader)

	select {
	case <-in.Done():
		if in.Err != nil {
			s.handleError(res, req, in.Err)
		} else {
			if err := writeNoContent(hw); err != nil {
				s.handleError(res, req, err)
			}
		}
	}
}