Merge pull request #189 from vith/expose-metadata-header-parsing-funcs

Expose ParseMetadataHeader and SerializeMetadataHeader functions
This commit is contained in:
Marius 2018-05-23 21:25:47 +02:00 committed by GitHub
commit 760de8f66a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 7 deletions

View File

@ -268,7 +268,7 @@ func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request)
}
// Parse metadata
meta := parseMeta(r.Header.Get("Upload-Metadata"))
meta := ParseMetadataHeader(r.Header.Get("Upload-Metadata"))
info := FileInfo{
Size: size,
@ -377,7 +377,7 @@ func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request)
}
if len(info.MetaData) != 0 {
w.Header().Set("Upload-Metadata", serializeMeta(info.MetaData))
w.Header().Set("Upload-Metadata", SerializeMetadataHeader(info.MetaData))
}
w.Header().Set("Cache-Control", "no-store")
@ -847,9 +847,10 @@ func (handler *UnroutedHandler) sizeOfUploads(ids []string) (size int64, err err
return
}
// Parse the Upload-Metadata header as defined in the File Creation extension.
// ParseMetadataHeader parses the Upload-Metadata header as defined in the
// File Creation extension.
// e.g. Upload-Metadata: name bHVucmpzLnBuZw==,type aW1hZ2UvcG5n
func parseMeta(header string) map[string]string {
func ParseMetadataHeader(header string) map[string]string {
meta := make(map[string]string)
for _, element := range strings.Split(header, ",") {
@ -875,10 +876,10 @@ func parseMeta(header string) map[string]string {
return meta
}
// Serialize a map of strings into the Upload-Metadata header format used in the
// response for HEAD requests.
// SerializeMetadataHeader serializes a map of strings into the Upload-Metadata
// header format used in the response for HEAD requests.
// e.g. Upload-Metadata: name bHVucmpzLnBuZw==,type aW1hZ2UvcG5n
func serializeMeta(meta map[string]string) string {
func SerializeMetadataHeader(meta map[string]string) string {
header := ""
for key, value := range meta {
valueBase64 := base64.StdEncoding.EncodeToString([]byte(value))