Skip to content

Commit

Permalink
Merge pull request #1 from wienczny/master
Browse files Browse the repository at this point in the history
'Set' headers instead of 'Add' to prevent duplicate header fields
  • Loading branch information
ian-kent committed May 20, 2015
2 parents cca240b + 515c1ca commit fec2db1
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions api/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func (apiv1 *APIv1) download(w http.ResponseWriter, req *http.Request) {

apiv1.defaultOptions(w, req)

w.Header().Add("Content-Type", "message/rfc822")
w.Header().Add("Content-Disposition", "attachment; filename=\""+id+".eml\"")
w.Header().Set("Content-Type", "message/rfc822")
w.Header().Set("Content-Disposition", "attachment; filename=\""+id+".eml\"")

switch apiv1.config.Storage.(type) {
case *storage.MongoDB:
Expand Down Expand Up @@ -185,17 +185,25 @@ func (apiv1 *APIv1) download_part(w http.ResponseWriter, req *http.Request) {
// TODO extension from content-type?
apiv1.defaultOptions(w, req)

w.Header().Add("Content-Disposition", "attachment; filename=\""+id+"-part-"+part+"\"")
w.Header().Set("Content-Disposition", "attachment; filename=\""+id+"-part-"+part+"\"")

message, _ := apiv1.config.Storage.Load(id)
contentTransferEncoding := ""
pid, _ := strconv.Atoi(part)
for h, l := range message.MIME.Parts[pid].Headers {
for _, v := range l {
if strings.ToLower(h) == "content-transfer-encoding" && contentTransferEncoding == "" {
contentTransferEncoding = v
switch strings.ToLower(h) {
case "content-disposition":
// Prevent duplicate "content-disposition"
w.Header().Set(h, v)
case "content-transfer-encoding":
if contentTransferEncoding == "" {
contentTransferEncoding = v
}
fallthrough
default:
w.Header().Add(h, v)
}
w.Header().Add(h, v)
}
}
body := []byte(message.MIME.Parts[pid].Body)
Expand Down

0 comments on commit fec2db1

Please sign in to comment.