Skip to content

Commit

Permalink
updates to address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gregns1 committed Jan 3, 2025
1 parent 2e354d1 commit e358f9c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
7 changes: 1 addition & 6 deletions rest/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2873,17 +2873,12 @@ func TestBufferFlush(t *testing.T) {
require.NoError(t, err)
require.NoError(t, a.Save(user))

// create some changes
for i := 0; i < 10; i++ {
rt.PutDoc(fmt.Sprint(i), `{"some":"doc", "channels":["foo"]}`)
}

var wg sync.WaitGroup
var resp *TestResponse
wg.Add(1)
go func() {
defer wg.Done()
resp = rt.SendUserRequest(http.MethodGet, "/{{.keyspace}}/_changes?feed=continuous&since=0&timeout=5000&include_docs=true", "", "foo")
resp = rt.SendUserRequest(http.MethodGet, "/{{.keyspace}}/_changes?feed=continuous&since=0&timeout=500&include_docs=true", "", "foo")
RequireStatus(t, resp, http.StatusOK)
}()
wg.Wait()
Expand Down
15 changes: 15 additions & 0 deletions rest/counted_response_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/couchbase/sync_gateway/base"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -169,3 +170,17 @@ func TestCountableResponseWriterWithDelay(t *testing.T) {
}

}

func TestResponseWriterSupportsFLush(t *testing.T) {
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {

stat, err := base.NewIntStat(base.SubsystemDatabaseKey, "http_bytes_written", base.StatUnitBytes, base.PublicRestBytesWrittenDesc, base.StatAddedVersion3dot1dot0, base.StatDeprecatedVersionNotDeprecated, base.StatStabilityCommitted, nil, nil, prometheus.CounterValue, 0)
require.NoError(t, err)
responseWriter := getResponseWriter(t, stat, test.name, 0)

_, ok := responseWriter.(http.Flusher)
assert.True(t, ok)
})
}
}
9 changes: 8 additions & 1 deletion rest/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ const (
minCompressibleJSONSize = 1000
)

var _ http.Flusher = &CountedResponseWriter{}
var _ http.Flusher = &NonCountedResponseWriter{}
var _ http.Flusher = &EncodedResponseWriter{}

var _ http.Hijacker = &CountedResponseWriter{}
var _ http.Hijacker = &NonCountedResponseWriter{}

var ErrInvalidLogin = base.HTTPErrorf(http.StatusUnauthorized, "Invalid login")
var ErrLoginRequired = base.HTTPErrorf(http.StatusUnauthorized, "Login required")

Expand Down Expand Up @@ -674,7 +681,7 @@ func (h *handler) validateAndWriteHeaders(method handlerMethod, accessPermission
// ensure wrapped ResponseWriter implements http.Flusher
_, ok := h.response.(http.Flusher)
if !ok {
return fmt.Errorf("ResponseWriter does not implement Flusher interface")
return fmt.Errorf("http.ResponseWriter %T does not implement Flusher interface", h.response)
}
return nil
}
Expand Down

0 comments on commit e358f9c

Please sign in to comment.