From 8acbc4cfdb39a681f425a0f1ef27fbd55aa71158 Mon Sep 17 00:00:00 2001 From: Jason Papakostas Date: Tue, 22 May 2018 11:46:18 -0500 Subject: [PATCH] Expose ParseMetadataHeader and SerializeMetadataHeader functions closes #186 --- unrouted_handler.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/unrouted_handler.go b/unrouted_handler.go index 38ad05e..c547fd2 100644 --- a/unrouted_handler.go +++ b/unrouted_handler.go @@ -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))