(w http.ResponseWriter, r *http.Request)
| 343 | } |
| 344 | |
| 345 | func mutationHandler(w http.ResponseWriter, r *http.Request) { |
| 346 | if commonHandler(w, r) { |
| 347 | return |
| 348 | } |
| 349 | |
| 350 | commitNow, err := parseBool(r, "commitNow") |
| 351 | if err != nil { |
| 352 | x.SetStatus(w, x.ErrorInvalidRequest, err.Error()) |
| 353 | return |
| 354 | } |
| 355 | startTs, err := parseUint64(r, "startTs") |
| 356 | hash := r.URL.Query().Get("hash") |
| 357 | if err != nil { |
| 358 | x.SetStatus(w, x.ErrorInvalidRequest, err.Error()) |
| 359 | return |
| 360 | } |
| 361 | body := readRequest(w, r) |
| 362 | if body == nil { |
| 363 | return |
| 364 | } |
| 365 | |
| 366 | // start parsing the query |
| 367 | parseStart := time.Now() |
| 368 | |
| 369 | var req *api.Request |
| 370 | contentType := r.Header.Get("Content-Type") |
| 371 | mediaType, contentTypeParams, err := mime.ParseMediaType(contentType) |
| 372 | if err != nil { |
| 373 | x.SetStatus(w, x.ErrorInvalidRequest, "Invalid Content-Type") |
| 374 | } |
| 375 | if charset, ok := contentTypeParams["charset"]; ok && strings.ToLower(charset) != "utf-8" { |
| 376 | x.SetStatus(w, x.ErrorInvalidRequest, "Unsupported charset. "+ |
| 377 | "Supported charset is UTF-8") |
| 378 | return |
| 379 | } |
| 380 | |
| 381 | switch mediaType { |
| 382 | case "application/json": |
| 383 | ms := make(map[string]*skipJSONUnmarshal) |
| 384 | if err := json.Unmarshal(body, &ms); err != nil { |
| 385 | jsonErr := convertJSONError(string(body), err) |
| 386 | x.SetStatus(w, x.ErrorInvalidRequest, jsonErr.Error()) |
| 387 | return |
| 388 | } |
| 389 | |
| 390 | req = &api.Request{} |
| 391 | if queryText, ok := ms["query"]; ok && queryText != nil { |
| 392 | req.Query, err = strconv.Unquote(string(queryText.bs)) |
| 393 | if err != nil { |
| 394 | x.SetStatus(w, x.ErrorInvalidRequest, err.Error()) |
| 395 | return |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | // JSON API support both keys 1. mutations 2. set,delete,cond |
| 400 | // We want to maintain the backward compatibility of the API here. |
| 401 | extractMutation := func(jsMap map[string]*skipJSONUnmarshal) (*api.Mutation, error) { |
| 402 | mu := &api.Mutation{} |
nothing calls this directly
no test coverage detected