MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / handleAllDocs

Method handleAllDocs

rest/bulk_api.go:51–276  ·  view source on GitHub ↗

HTTP handler for _all_docs

()

Source from the content-addressed store, hash-verified

49
50// HTTP handler for _all_docs
51func (h *handler) handleAllDocs() error {
52
53 var numDocsPreFilter, numDocsPostFilter uint64
54 if h.privs != adminPrivs {
55 defer func() {
56 // public _all_docs stats
57 h.db.DbStats.DatabaseStats.NumPublicAllDocsRequests.Add(1)
58 if numDocsPreFilter > 0 {
59 h.db.DbStats.DatabaseStats.NumDocsPreFilterPublicAllDocs.Add(int64(numDocsPreFilter))
60 }
61 if numDocsPostFilter > 0 {
62 h.db.DbStats.DatabaseStats.NumDocsPostFilterPublicAllDocs.Add(int64(numDocsPostFilter))
63 }
64 }()
65 }
66
67 if h.privs != adminPrivs && h.db.DatabaseContext.Options.DisablePublicAllDocs {
68 return base.HTTPErrorf(http.StatusForbidden, "public access to _all_docs is disabled for this database")
69 }
70
71 // http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
72 includeDocs := h.getBoolQuery("include_docs")
73 includeChannels := h.getBoolQuery("channels")
74 includeAccess := h.getBoolQuery("access") && h.user == nil
75 includeRevs := h.getBoolQuery("revs")
76 includeSeqs := h.getBoolQuery("update_seq")
77
78 // Get the doc IDs if this is a POST request:
79 var explicitDocIDs []string
80 if h.rq.Method == "POST" {
81 input, err := h.readJSON()
82 if err == nil {
83 if explicitDocIDs, _ = db.GetStringArrayProperty(input, "keys"); explicitDocIDs == nil {
84 err = base.HTTPErrorf(http.StatusBadRequest, "Bad/missing keys")
85 }
86 }
87 if err != nil {
88 return err
89 }
90 } else if h.rq.Method == "GET" {
91 var err error
92 if explicitDocIDs, err = h.getJSONStringArrayQuery("keys"); err != nil {
93 return base.HTTPErrorf(http.StatusBadRequest, "Bad keys")
94 }
95 }
96
97 // Get the set of channels the user has access to; nil if user is admin or has access to user "*"
98 var availableChannels ch.TimedSet
99 if h.user != nil {
100 var err error
101 availableChannels, err = h.user.InheritedCollectionChannels(h.collection.ScopeName, h.collection.Name)
102 if err != nil {
103 return err
104 }
105 if availableChannels == nil {
106 base.AssertfCtx(h.ctx(), "User %q has no channels in handleAllDocs", base.UD(h.user.Name()))
107 return base.HTTPErrorf(http.StatusInternalServerError, "user has no channels")
108 }

Callers

nothing calls this directly

Calls 15

getBoolQueryMethod · 0.95
readJSONMethod · 0.95
ctxMethod · 0.95
ContainsMethod · 0.95
addJSONMethod · 0.95
getJSONStringQueryMethod · 0.95
getIntQueryMethod · 0.95
setHeaderMethod · 0.95
writeStatusMethod · 0.95
HTTPErrorfFunction · 0.92
GetStringArrayPropertyFunction · 0.92

Tested by

no test coverage detected