HTTP handler for a POST to a database (creating a document)
()
| 743 | |
| 744 | // HTTP handler for a POST to a database (creating a document) |
| 745 | func (h *handler) handlePostDoc() error { |
| 746 | if h.isReadOnlyGuest() { |
| 747 | return base.HTTPErrorf(http.StatusForbidden, auth.GuestUserReadOnly) |
| 748 | } |
| 749 | |
| 750 | if h.db.DatabaseContext.Options.UnsupportedOptions != nil && h.db.DatabaseContext.Options.UnsupportedOptions.RejectWritesWithSkippedSequences { |
| 751 | // if we are in slow broadcast mode reject write with 503 and increment rejected writes stat |
| 752 | if h.db.BroadcastSlowMode.Load() { |
| 753 | h.db.DbStats.DatabaseStats.NumDocWritesRejected.Add(1) |
| 754 | return base.HTTPErrorf(http.StatusServiceUnavailable, "Database cache is behind and cannot accept writes at this time. Please try again later.") |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | roundTrip := h.getBoolQuery("roundtrip") |
| 759 | body, err := h.readDocument() |
| 760 | if err != nil { |
| 761 | return err |
| 762 | } |
| 763 | |
| 764 | docid, newRev, doc, err := h.collection.Post(h.ctx(), body) |
| 765 | if err != nil { |
| 766 | return err |
| 767 | } |
| 768 | |
| 769 | if doc != nil && roundTrip { |
| 770 | err := h.collection.WaitForSequenceNotSkipped(h.ctx(), doc.Sequence) |
| 771 | if err != nil { |
| 772 | return err |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | h.setHeader("Location", docid) |
| 777 | h.setEtag(newRev) |
| 778 | |
| 779 | h.writeRawJSONStatus(http.StatusOK, []byte(`{"id":`+base.ConvertToJSONString(docid)+`,"ok":true,"rev":"`+newRev+`","cv":"`+doc.HLV.GetCurrentVersionString()+`"}`)) |
| 780 | return nil |
| 781 | } |
| 782 | |
| 783 | // docVersionFromOCCValue converts an OCC value and type into a DocVersion struct. |
| 784 | func docVersionFromOCCValue(occValue string, occValueType occVersionType) (docVersion db.DocVersion, err error) { |
nothing calls this directly
no test coverage detected