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

Method handleChanges

rest/changes_api.go:166–368  ·  view source on GitHub ↗

Top-level handler for _changes feed requests. Accepts GET or POST requests.

()

Source from the content-addressed store, hash-verified

164
165// Top-level handler for _changes feed requests. Accepts GET or POST requests.
166func (h *handler) handleChanges() error {
167 // http://wiki.apache.org/couchdb/HTTP_database_API#Changes
168 // http://docs.couchdb.org/en/latest/api/database/changes.html
169
170 var feed string
171 var options db.ChangesOptions
172 var filter string
173 var channelsArray []string
174 var docIdsArray []string
175
176 if h.rq.Method == "GET" {
177 // GET request has parameters in URL:
178 feed = h.getQuery("feed")
179 var err error
180 if options.Since, err = db.ParsePlainSequenceID(h.getJSONStringQuery("since")); err != nil {
181 return err
182 }
183 options.Limit = int(h.getIntQuery("limit", 0))
184 options.Conflicts = h.getQuery("style") == "all_docs"
185 options.ActiveOnly = h.getBoolQuery("active_only")
186 options.IncludeDocs = h.getBoolQuery("include_docs")
187 options.Revocations = h.getBoolQuery("revocations")
188 options.VersionType, err = db.ParseChangesVersionType(h.getQuery("version_type"))
189 if err != nil {
190 return base.HTTPErrorf(http.StatusBadRequest, "Invalid version_type: %v", err)
191 }
192
193 if options.Conflicts && options.VersionType == db.ChangesVersionTypeCV {
194 return base.HTTPErrorf(http.StatusBadRequest, "Cannot use 'style=all_docs' with 'version_type=cv'")
195 }
196
197 useRequestPlus, _ := h.getOptBoolQuery("request_plus", h.db.Options.ChangesRequestPlus)
198 if useRequestPlus && feed != feedTypeContinuous {
199 var seqErr error
200 options.RequestPlusSeq, seqErr = h.db.GetRequestPlusSequence()
201 if seqErr != nil {
202 return base.HTTPErrorf(http.StatusServiceUnavailable, "Unable to retrieve requestPlus sequence")
203 }
204
205 }
206 filter = h.getQuery("filter")
207 channelsParam := h.getQuery("channels")
208 if channelsParam != "" {
209 channelsArray = strings.Split(channelsParam, ",")
210 }
211
212 docidsParam := h.getQuery("doc_ids")
213 if docidsParam != "" {
214 var docidKeys []string
215 err := base.JSONUnmarshal([]byte(docidsParam), &docidKeys)
216 if err == nil {
217 if len(docidKeys) > 0 {
218 docIdsArray = docidKeys
219 }
220 } else {
221 // This is not a JSON array so treat as a simple
222 // comma separated list of doc id's
223 docIdsArray = strings.Split(docidsParam, ",")

Callers

nothing calls this directly

Calls 15

getQueryMethod · 0.95
getJSONStringQueryMethod · 0.95
getIntQueryMethod · 0.95
getBoolQueryMethod · 0.95
getOptBoolQueryMethod · 0.95
getQueryValuesMethod · 0.95
readBodyMethod · 0.95
ctxMethod · 0.95
auditChangesFeedStartMethod · 0.95
sendSimpleChangesMethod · 0.95

Tested by

no test coverage detected