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

Method handleDumpChannel

rest/bulk_api.go:357–384  ·  view source on GitHub ↗

HTTP handler for _dumpchannel

()

Source from the content-addressed store, hash-verified

355
356// HTTP handler for _dumpchannel
357func (h *handler) handleDumpChannel() error {
358 channelName := h.PathVar("channel")
359 since := h.getIntQuery("since", 0)
360 base.InfofCtx(h.ctx(), base.KeyHTTP, "Dump channel %q", base.UD(channelName))
361
362 chanLog, _ := h.collection.GetChangeLog(h.ctx(), ch.NewID(channelName, h.collection.GetCollectionID()), since)
363 if chanLog == nil {
364 return base.HTTPErrorf(http.StatusNotFound, "no such channel")
365 }
366 title := fmt.Sprintf("/%s: “%s” Channel", html.EscapeString(h.db.Name), html.EscapeString(channelName))
367 h.setHeader("Content-Type", `text/html; charset="UTF-8"`)
368 _, _ = h.response.Write([]byte(fmt.Sprintf(
369 `<!DOCTYPE html><html><head><title>%s</title></head><body>
370 <h1>%s</h1><code>
371 <p>Since = %d</p>
372 <table border=1>
373 `,
374 title, title, chanLog[0].Sequence-1)))
375 _, _ = h.response.Write([]byte("\t<tr><th>Seq</th><th>Doc</th><th>Rev</th><th>Flags</th></tr>\n"))
376 for _, entry := range chanLog {
377 _, _ = h.response.Write([]byte(fmt.Sprintf("\t<tr><td>%d</td><td>%s</td><td>%s</td><td>%08b</td>",
378 entry.Sequence,
379 html.EscapeString(entry.DocID), html.EscapeString(entry.RevID), entry.Flags)))
380 _, _ = h.response.Write([]byte("</tr>\n"))
381 }
382 _, _ = h.response.Write([]byte("</table>\n</code></html></body>"))
383 return nil
384}
385
386// HTTP handler for a POST to _bulk_get
387// Request looks like POST /db/_bulk_get?revs=___&attachments=___

Callers

nothing calls this directly

Calls 10

PathVarMethod · 0.95
getIntQueryMethod · 0.95
ctxMethod · 0.95
setHeaderMethod · 0.95
InfofCtxFunction · 0.92
UDFunction · 0.92
HTTPErrorfFunction · 0.92
GetChangeLogMethod · 0.80
GetCollectionIDMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected