(docid string, roundTrip bool)
| 665 | } |
| 666 | |
| 667 | func (h *handler) handlePutDocReplicator2(docid string, roundTrip bool) (err error) { |
| 668 | if !base.IsEnterpriseEdition() { |
| 669 | return base.HTTPErrorf(http.StatusNotImplemented, "replicator2 endpoints are only supported in EE") |
| 670 | } |
| 671 | if h.isReadOnlyGuest() { |
| 672 | return base.HTTPErrorf(http.StatusForbidden, auth.GuestUserReadOnly) |
| 673 | } |
| 674 | |
| 675 | bodyBytes, err := h.readBody() |
| 676 | if err != nil { |
| 677 | return err |
| 678 | } |
| 679 | if bodyBytes == nil || len(bodyBytes) == 0 { |
| 680 | return base.ErrEmptyDocument |
| 681 | } |
| 682 | |
| 683 | newDoc := &db.Document{ |
| 684 | ID: docid, |
| 685 | } |
| 686 | newDoc.UpdateBodyBytes(bodyBytes) |
| 687 | |
| 688 | var parentRev string |
| 689 | if oldRev := h.getQuery("rev"); oldRev != "" { |
| 690 | parentRev = oldRev |
| 691 | } else if ifMatch, _ := h.getEtag("If-Match"); ifMatch != "" { |
| 692 | parentRev = ifMatch |
| 693 | } |
| 694 | |
| 695 | generation, _ := db.ParseRevID(h.ctx(), parentRev) |
| 696 | generation++ |
| 697 | |
| 698 | deleted, _ := h.getOptBoolQuery("deleted", false) |
| 699 | newDoc.Deleted = deleted |
| 700 | |
| 701 | newDoc.RevID = db.CreateRevIDWithBytes(generation, parentRev, bodyBytes) |
| 702 | history := []string{newDoc.RevID} |
| 703 | |
| 704 | if parentRev != "" { |
| 705 | history = append(history, parentRev) |
| 706 | } |
| 707 | |
| 708 | // Handle and pull out expiry |
| 709 | if bytes.Contains(bodyBytes, []byte(db.BodyExpiry)) { |
| 710 | body := newDoc.Body(h.ctx()) |
| 711 | expiry, err := body.ExtractExpiry() |
| 712 | if err != nil { |
| 713 | return base.HTTPErrorf(http.StatusBadRequest, "Invalid expiry: %v", err) |
| 714 | } |
| 715 | newDoc.DocExpiry = expiry |
| 716 | newDoc.UpdateBody(body) |
| 717 | } |
| 718 | |
| 719 | // Pull out attachments |
| 720 | if bytes.Contains(bodyBytes, []byte(db.BodyAttachments)) { |
| 721 | body := newDoc.Body(h.ctx()) |
| 722 | |
| 723 | newDoc.SetAttachments(db.GetBodyAttachments(body)) |
| 724 | delete(body, db.BodyAttachments) |
no test coverage detected