diff options
| author | Shulhan <ms@kilabit.info> | 2022-04-22 23:17:32 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-04-22 23:30:56 +0700 |
| commit | 02abbfec6842d4ef7cc90cec37d0ffb4e39f6892 (patch) | |
| tree | 1cc6da04dba937ba2c7ed295293136648c900831 /httpd.go | |
| parent | 00ecc95e8af5d2e15927579894f2f92346453134 (diff) | |
| download | rescached-02abbfec6842d4ef7cc90cec37d0ffb4e39f6892.tar.xz | |
all: changes the block.d update API request type to x-www-form-urlencoded
Instead of passing whole block.d object with single field Name set,
send the request using urlencoded form.
Diffstat (limited to 'httpd.go')
| -rw-r--r-- | httpd.go | 19 |
1 files changed, 6 insertions, 13 deletions
@@ -153,7 +153,7 @@ func (srv *Server) httpdRegisterEndpoints() (err error) { err = srv.httpd.RegisterEndpoint(&libhttp.Endpoint{ Method: libhttp.RequestMethodPost, Path: apiBlockdUpdate, - RequestType: libhttp.RequestTypeJSON, + RequestType: libhttp.RequestTypeForm, ResponseType: libhttp.ResponseTypeJSON, Call: srv.httpApiBlockdUpdate, }) @@ -347,17 +347,15 @@ func (srv *Server) httpApiBlockdEnable(epr *libhttp.EndpointRequest) (resBody [] return json.Marshal(&res) } -// httpApiBlockdUpdate fetch the latest hosts file from the hosts block -// provider based on registered URL. +// httpApiBlockdUpdate fetch the latest hosts file from the block.d provider +// based on registered URL. // // # Request // // POST /api/block.d/update -// Content-Type: application/json +// Content-Type: application/x-www-form-urlencoded // -// { -// "Name": <block.d name> -// } +// Name=<block.d name> // // # Response // @@ -372,12 +370,7 @@ func (srv *Server) httpApiBlockdUpdate(epr *libhttp.EndpointRequest) (resBody [] hbName string ) - err = json.Unmarshal(epr.RequestBody, &hb) - if err != nil { - return nil, fmt.Errorf("%s: %w", logp, err) - } - - hbName = strings.ToLower(hb.Name) + hbName = strings.ToLower(epr.HttpRequest.Form.Get(paramNameName)) hb = srv.env.HostsBlocks[hbName] if hb == nil { |
