From 02abbfec6842d4ef7cc90cec37d0ffb4e39f6892 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 22 Apr 2022 23:17:32 +0700 Subject: 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. --- httpd.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'httpd.go') diff --git a/httpd.go b/httpd.go index c1ced0c..d1f2dda 100644 --- a/httpd.go +++ b/httpd.go @@ -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": -// } +// 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 { -- cgit v1.3