UpdateChangesOptionsFromQuery handles any changes POST requests that send parameters in the POST body AND in the query string. If any parameters are present in the query string, they override the values sent in the body.
(feed *string, options *db.ChangesOptions, filter *string, channelsArray []string, docIdsArray []string)
| 77 | // are present in the query string, they override the values sent in the body. |
| 78 | |
| 79 | func (h *handler) updateChangesOptionsFromQuery(feed *string, options *db.ChangesOptions, filter *string, channelsArray []string, docIdsArray []string) (newChannelsArray []string, newDocIdsArray []string, err error) { |
| 80 | |
| 81 | if h.rq.URL.RawQuery == "" { |
| 82 | return channelsArray, docIdsArray, nil |
| 83 | } |
| 84 | |
| 85 | values := h.getQueryValues() |
| 86 | |
| 87 | if _, ok := values["feed"]; ok { |
| 88 | *feed = h.getQuery("feed") |
| 89 | } |
| 90 | |
| 91 | if _, ok := values["since"]; ok { |
| 92 | if options.Since, err = db.ParsePlainSequenceID(h.getJSONStringQuery("since")); err != nil { |
| 93 | return nil, nil, err |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | if _, ok := values["limit"]; ok { |
| 98 | options.Limit = int(h.getIntQuery("limit", 0)) |
| 99 | } |
| 100 | |
| 101 | if _, ok := values["style"]; ok { |
| 102 | options.Conflicts = (h.getQuery("style") == "all_docs") |
| 103 | } |
| 104 | |
| 105 | if _, ok := values["active_only"]; ok { |
| 106 | options.ActiveOnly = h.getBoolQuery("active_only") |
| 107 | } |
| 108 | |
| 109 | if _, ok := values["include_docs"]; ok { |
| 110 | options.IncludeDocs = (h.getBoolQuery("include_docs")) |
| 111 | } |
| 112 | |
| 113 | if _, ok := values["filter"]; ok { |
| 114 | *filter = h.getQuery("filter") |
| 115 | } |
| 116 | |
| 117 | if _, ok := values["channels"]; ok { |
| 118 | channelsParam := h.getQuery("channels") |
| 119 | if channelsParam != "" { |
| 120 | channelsArray = strings.Split(channelsParam, ",") |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | if _, ok := values["doc_ids"]; ok { |
| 125 | docidsParam := h.getQuery("doc_ids") |
| 126 | if docidsParam != "" { |
| 127 | var querydocidKeys []string |
| 128 | err := base.JSONUnmarshal([]byte(docidsParam), &querydocidKeys) |
| 129 | if err == nil { |
| 130 | if len(querydocidKeys) > 0 { |
| 131 | docIdsArray = querydocidKeys |
| 132 | } |
| 133 | } else { |
| 134 | // This is not a JSON array so treat as a simple |
| 135 | // comma separated list of doc id's |
| 136 | docIdsArray = strings.Split(docidsParam, ",") |
no test coverage detected