HTTP handler for a GET of a document
()
| 26 | |
| 27 | // HTTP handler for a GET of a document |
| 28 | func (h *handler) handleGetDoc() error { |
| 29 | docid := h.PathVar("docid") |
| 30 | rev := h.getQuery("rev") // Empty, RevTree ID, or CV |
| 31 | openRevs := h.getQuery("open_revs") |
| 32 | showExp := h.getBoolQuery("show_exp") |
| 33 | const showCV = true // Post-beta 4.0 _always_ returns CV - negligible impact to revtree-only clients and promotes CV as the preferred OCC value |
| 34 | |
| 35 | if replicator2, _ := h.getOptBoolQuery("replicator2", false); replicator2 { |
| 36 | return h.handleGetDocReplicator2(docid, rev) |
| 37 | } |
| 38 | |
| 39 | // Extra validation of these options, since this combination isn't valid anyway. We want to prevent users from attempting to use CV with open_revs. |
| 40 | if openRevs != "" && rev != "" { |
| 41 | return base.HTTPErrorf(http.StatusBadRequest, "cannot specify both 'rev' and 'open_revs' query parameters") |
| 42 | } |
| 43 | |
| 44 | // We'll treat empty rev as a RevTree ID, which only affects what the ETag looks like. |
| 45 | // If the user specifically asked for a CV, they'll get a CV ETag - but everything else can stay as RevTree ID for compatibility. |
| 46 | isRevTreeID := rev == "" || base.IsRevTreeID(rev) |
| 47 | |
| 48 | // Check whether the caller wants a revision history, or attachment bodies, or both: |
| 49 | var revsLimit = 0 |
| 50 | var revsFrom, attachmentsSince []string |
| 51 | { |
| 52 | var err error |
| 53 | var attsSinceParam, revsFromParam []string |
| 54 | if revsFromParam, err = h.getJSONStringArrayQuery("revs_from"); err != nil { |
| 55 | return err |
| 56 | } |
| 57 | if attsSinceParam, err = h.getJSONStringArrayQuery("atts_since"); err != nil { |
| 58 | return err |
| 59 | } |
| 60 | |
| 61 | if h.getBoolQuery("revs") { |
| 62 | revsLimit = int(h.getIntQuery("revs_limit", math.MaxInt32)) |
| 63 | if revsFromParam != nil { |
| 64 | revsFrom = revsFromParam |
| 65 | } else { |
| 66 | revsFrom = attsSinceParam // revs_from defaults to same value as atts_since |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | if h.getBoolQuery("attachments") { |
| 71 | if attsSinceParam != nil { |
| 72 | attachmentsSince = attsSinceParam |
| 73 | } else { |
| 74 | attachmentsSince = []string{} |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if openRevs == "" { |
| 80 | // Single-revision GET: |
| 81 | value, err := h.collection.Get1xRevBodyWithHistory(h.ctx(), docid, rev, db.Get1xRevBodyOptions{ |
| 82 | MaxHistory: revsLimit, |
| 83 | HistoryFrom: revsFrom, |
| 84 | AttachmentsSince: attachmentsSince, |
| 85 | ShowExp: showExp, |
nothing calls this directly
no test coverage detected