|
19 | 19 | package propfind
|
20 | 20 |
|
21 | 21 | import (
|
| 22 | + "bytes" |
22 | 23 | "context"
|
23 | 24 | "encoding/json"
|
24 | 25 | "encoding/xml"
|
@@ -218,7 +219,7 @@ func (p *Handler) propfindResponse(ctx context.Context, w http.ResponseWriter, r
|
218 | 219 | }
|
219 | 220 |
|
220 | 221 | w.WriteHeader(http.StatusMultiStatus)
|
221 |
| - if _, err := w.Write([]byte(propRes)); err != nil { |
| 222 | + if _, err := w.Write(propRes); err != nil { |
222 | 223 | log.Err(err).Msg("error writing response")
|
223 | 224 | }
|
224 | 225 | }
|
@@ -545,24 +546,26 @@ func ReadPropfind(r io.Reader) (pf XML, status int, err error) {
|
545 | 546 | }
|
546 | 547 |
|
547 | 548 | // MultistatusResponse converts a list of resource infos into a multistatus response string
|
548 |
| -func MultistatusResponse(ctx context.Context, pf *XML, mds []*provider.ResourceInfo, publicURL, ns string, linkshares map[string]struct{}) (string, error) { |
| 549 | +func MultistatusResponse(ctx context.Context, pf *XML, mds []*provider.ResourceInfo, publicURL, ns string, linkshares map[string]struct{}) ([]byte, error) { |
549 | 550 | responses := make([]*ResponseXML, 0, len(mds))
|
550 | 551 | for i := range mds {
|
551 | 552 | res, err := mdToPropResponse(ctx, pf, mds[i], publicURL, ns, linkshares)
|
552 | 553 | if err != nil {
|
553 |
| - return "", err |
| 554 | + return nil, err |
554 | 555 | }
|
555 | 556 | responses = append(responses, res)
|
556 | 557 | }
|
557 | 558 | responsesXML, err := xml.Marshal(&responses)
|
558 | 559 | if err != nil {
|
559 |
| - return "", err |
| 560 | + return nil, err |
560 | 561 | }
|
561 | 562 |
|
562 |
| - msg := `<?xml version="1.0" encoding="utf-8"?><d:multistatus xmlns:d="DAV:" ` |
563 |
| - msg += `xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns">` |
564 |
| - msg += string(responsesXML) + `</d:multistatus>` |
565 |
| - return msg, nil |
| 563 | + var buf bytes.Buffer |
| 564 | + buf.WriteString(`<?xml version="1.0" encoding="utf-8"?><d:multistatus xmlns:d="DAV:" `) |
| 565 | + buf.WriteString(`xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns">`) |
| 566 | + buf.Write(responsesXML) |
| 567 | + buf.WriteString(`</d:multistatus>`) |
| 568 | + return buf.Bytes(), nil |
566 | 569 | }
|
567 | 570 |
|
568 | 571 | // mdToPropResponse converts the CS3 metadata into a webdav PropResponse
|
@@ -590,7 +593,7 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
|
590 | 593 | // -2 indicates unknown (default)
|
591 | 594 | // -3 indicates unlimited
|
592 | 595 | quota := net.PropQuotaUnknown
|
593 |
| - size := fmt.Sprintf("%d", md.Size) |
| 596 | + size := strconv.FormatUint(md.Size, 10) |
594 | 597 | // TODO refactor helper functions: GetOpaqueJSONEncoded(opaque, key string, *struct) err, GetOpaquePlainEncoded(opaque, key) value, err
|
595 | 598 | // or use ok like pattern and return bool?
|
596 | 599 | if md.Opaque != nil && md.Opaque.Map != nil {
|
@@ -693,15 +696,15 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
|
693 | 696 | } else {
|
694 | 697 | checksums.WriteString(" MD5:")
|
695 | 698 | }
|
696 |
| - checksums.WriteString(string(e.Value)) |
| 699 | + checksums.Write(e.Value) |
697 | 700 | }
|
698 | 701 | if e, ok := md.Opaque.Map["adler32"]; ok {
|
699 | 702 | if checksums.Len() == 0 {
|
700 | 703 | checksums.WriteString("<oc:checksum>ADLER32:")
|
701 | 704 | } else {
|
702 | 705 | checksums.WriteString(" ADLER32:")
|
703 | 706 | }
|
704 |
| - checksums.WriteString(string(e.Value)) |
| 707 | + checksums.Write(e.Value) |
705 | 708 | }
|
706 | 709 | }
|
707 | 710 | if checksums.Len() > 0 {
|
@@ -861,15 +864,15 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
|
861 | 864 | } else {
|
862 | 865 | checksums.WriteString(" MD5:")
|
863 | 866 | }
|
864 |
| - checksums.WriteString(string(e.Value)) |
| 867 | + checksums.Write(e.Value) |
865 | 868 | }
|
866 | 869 | if e, ok := md.Opaque.Map["adler32"]; ok {
|
867 | 870 | if checksums.Len() == 0 {
|
868 | 871 | checksums.WriteString("<oc:checksum>ADLER32:")
|
869 | 872 | } else {
|
870 | 873 | checksums.WriteString(" ADLER32:")
|
871 | 874 | }
|
872 |
| - checksums.WriteString(string(e.Value)) |
| 875 | + checksums.Write(e.Value) |
873 | 876 | }
|
874 | 877 | }
|
875 | 878 | if checksums.Len() > 13 {
|
|
0 commit comments