mirror of
https://github.com/minio/minio.git
synced 2026-02-12 05:40:16 -05:00
api: extract http headers with some supported header list. (#2268)
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"encoding/xml"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -84,3 +85,36 @@ func TestIsValidLocationContraint(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tests validate metadata extraction from http headers.
|
||||
func TestExtractMetadataHeaders(t *testing.T) {
|
||||
testCases := []struct {
|
||||
header http.Header
|
||||
metadata map[string]string
|
||||
}{
|
||||
// Validate if there a known 'content-type'.
|
||||
{
|
||||
header: http.Header{
|
||||
"Content-Type": []string{"image/png"},
|
||||
},
|
||||
metadata: map[string]string{
|
||||
"content-type": "image/png",
|
||||
},
|
||||
},
|
||||
// Validate if there are no keys to extract.
|
||||
{
|
||||
header: http.Header{
|
||||
"test-1": []string{"123"},
|
||||
},
|
||||
metadata: map[string]string{},
|
||||
},
|
||||
}
|
||||
|
||||
// Validate if the extracting headers.
|
||||
for i, testCase := range testCases {
|
||||
metadata := extractMetadataFromHeader(testCase.header)
|
||||
if !reflect.DeepEqual(metadata, testCase.metadata) {
|
||||
t.Fatalf("Test %d failed: Expected \"%#v\", got \"%#v\"", i+1, testCase.metadata, metadata)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user