Add Content-Length and Content-Disposition Header
for GetFileContent route.
This commit is contained in:
48
pkg/nullio/content_length_test.go
Normal file
48
pkg/nullio/content_length_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package nullio
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type responseWriterStub struct {
|
||||
bytes.Buffer
|
||||
header http.Header
|
||||
}
|
||||
|
||||
func (r *responseWriterStub) Header() http.Header {
|
||||
return r.header
|
||||
}
|
||||
func (r *responseWriterStub) WriteHeader(_ int) {
|
||||
}
|
||||
|
||||
func TestContentLengthWriter_Write(t *testing.T) {
|
||||
header := http.Header(make(map[string][]string))
|
||||
buf := &responseWriterStub{header: header}
|
||||
writer := &ContentLengthWriter{Target: buf}
|
||||
part1 := []byte("-rw-rw-r-- 1 kali ka")
|
||||
contentLength := "42"
|
||||
part2 := []byte("li " + contentLength + " 1660763446 flag\nFL")
|
||||
part3 := []byte("AG")
|
||||
|
||||
count, err := writer.Write(part1)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(part1), count)
|
||||
assert.Empty(t, buf.String())
|
||||
assert.Equal(t, "", header.Get("Content-Length"))
|
||||
|
||||
count, err = writer.Write(part2)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(part2), count)
|
||||
assert.Equal(t, "FL", buf.String())
|
||||
assert.Equal(t, contentLength, header.Get("Content-Length"))
|
||||
|
||||
count, err = writer.Write(part3)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(part3), count)
|
||||
assert.Equal(t, "FLAG", buf.String())
|
||||
assert.Equal(t, contentLength, header.Get("Content-Length"))
|
||||
}
|
Reference in New Issue
Block a user