mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-13 21:02:25 +03:00
Implement MSC3916 (#3397)
Needs https://github.com/matrix-org/gomatrixserverlib/pull/437
This commit is contained in:
parent
8c6cf51b8f
commit
7a4ef240fc
13 changed files with 364 additions and 45 deletions
|
@ -1,8 +1,13 @@
|
|||
package routing
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/matrix-org/dendrite/mediaapi/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -11,3 +16,28 @@ func Test_dispositionFor(t *testing.T) {
|
|||
assert.Equal(t, "attachment", contentDispositionFor("image/svg"), "image/svg")
|
||||
assert.Equal(t, "inline", contentDispositionFor("image/jpeg"), "image/jpg")
|
||||
}
|
||||
|
||||
func Test_Multipart(t *testing.T) {
|
||||
r := &downloadRequest{
|
||||
MediaMetadata: &types.MediaMetadata{},
|
||||
}
|
||||
data := bytes.Buffer{}
|
||||
responseBody := "This media is plain text. Maybe somebody used it as a paste bin."
|
||||
data.WriteString(responseBody)
|
||||
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
_, err := multipartResponse(w, r, "text/plain", &data)
|
||||
assert.NoError(t, err)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
resp, err := srv.Client().Get(srv.URL)
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
// contentLength is always 0, since there's no Content-Length header on the multipart part.
|
||||
err, _, reader := parseMultipartResponse(r, resp, 1000)
|
||||
assert.NoError(t, err)
|
||||
gotResponse, err := io.ReadAll(reader)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, responseBody, string(gotResponse))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue