From c93cb43db856e43df2013d758c8c2b90391fdcc4 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Mon, 3 Jun 2019 12:03:45 +0300 Subject: [PATCH] * /remove_url: use JSON input data format --- control.go | 19 +++++++++---------- openapi/openapi.yaml | 22 ++++++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/control.go b/control.go index 77970de2..5e8f0e7a 100644 --- a/control.go +++ b/control.go @@ -676,19 +676,18 @@ func handleFilteringAddURL(w http.ResponseWriter, r *http.Request) { func handleFilteringRemoveURL(w http.ResponseWriter, r *http.Request) { log.Tracef("%s %v", r.Method, r.URL) - parameters, err := parseParametersFromBody(r.Body) + + type request struct { + URL string `json:"url"` + } + req := request{} + err := json.NewDecoder(r.Body).Decode(&req) if err != nil { - httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) + httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err) return } - url, ok := parameters["url"] - if !ok { - http.Error(w, "URL parameter was not specified", http.StatusBadRequest) - return - } - - if valid := govalidator.IsRequestURL(url); !valid { + if valid := govalidator.IsRequestURL(req.URL); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) return } @@ -697,7 +696,7 @@ func handleFilteringRemoveURL(w http.ResponseWriter, r *http.Request) { config.Lock() newFilters := config.Filters[:0] for _, filter := range config.Filters { - if filter.URL != url { + if filter.URL != req.URL { newFilters = append(newFilters, filter) } else { // Remove the filter file diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index d31f937f..385ac057 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -484,15 +484,13 @@ paths: operationId: filteringRemoveURL summary: 'Remove filter URL' consumes: - - text/plain + - application/json parameters: - - in: body - name: url - description: 'Previously added URL containing filtering rules' - required: true - schema: - type: string - example: 'url=https://filters.adtidy.org/windows/filters/15.txt' + - in: "body" + name: "body" + required: true + schema: + $ref: "#/definitions/RemoveUrlRequest" responses: 200: description: OK @@ -1298,6 +1296,14 @@ definitions: description: "URL containing filtering rules" type: "string" example: "https://filters.adtidy.org/windows/filters/15.txt" + RemoveUrlRequest: + type: "object" + description: "/remove_url request data" + properties: + url: + description: "Previously added URL containing filtering rules" + type: "string" + example: "https://filters.adtidy.org/windows/filters/15.txt" QueryLogItem: type: "object" description: "Query log item"