ParseMetadataHeader parses the Upload-Metadata header as defined in the File Creation extension. e.g. Upload-Metadata: name bHVucmpzLnBuZw==,type aW1hZ2UvcG5n
(header string)
| 1578 | // File Creation extension. |
| 1579 | // e.g. Upload-Metadata: name bHVucmpzLnBuZw==,type aW1hZ2UvcG5n |
| 1580 | func ParseMetadataHeader(header string) map[string]string { |
| 1581 | meta := make(map[string]string) |
| 1582 | |
| 1583 | for element := range strings.SplitSeq(header, ",") { |
| 1584 | element := strings.TrimSpace(element) |
| 1585 | |
| 1586 | parts := strings.Split(element, " ") |
| 1587 | |
| 1588 | if len(parts) > 2 { |
| 1589 | continue |
| 1590 | } |
| 1591 | |
| 1592 | key := parts[0] |
| 1593 | if key == "" { |
| 1594 | continue |
| 1595 | } |
| 1596 | |
| 1597 | value := "" |
| 1598 | if len(parts) == 2 { |
| 1599 | // Ignore current element if the value is no valid base64 |
| 1600 | dec, err := base64.StdEncoding.DecodeString(parts[1]) |
| 1601 | if err != nil { |
| 1602 | continue |
| 1603 | } |
| 1604 | |
| 1605 | value = string(dec) |
| 1606 | } |
| 1607 | |
| 1608 | meta[key] = value |
| 1609 | } |
| 1610 | |
| 1611 | return meta |
| 1612 | } |
| 1613 | |
| 1614 | // SerializeMetadataHeader serializes a map of strings into the Upload-Metadata |
| 1615 | // header format used in the response for HEAD requests. |
no outgoing calls
searching dependent graphs…