From 6311bf1dd7062c98db93767fcdd30bbc061f7513 Mon Sep 17 00:00:00 2001 From: Nikita Tokarchuk Date: Thu, 16 Dec 2021 21:29:43 +0100 Subject: [PATCH] Make initial request setup in the external private function --- frontend/ghost/client.go | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/frontend/ghost/client.go b/frontend/ghost/client.go index 1b28c3b..5f26742 100644 --- a/frontend/ghost/client.go +++ b/frontend/ghost/client.go @@ -56,17 +56,7 @@ func (g *HTTPClient) doQuery(method string, v easyjson.Unmarshaler, params ...Qu fasthttp.ReleaseRequest(req) }() - uri := req.URI() - uri.SetHost(g.Addr) - uri.SetPath(method) - uri.QueryArgs().Add("key", g.ContentKey) - if g.client.IsTLS { - uri.SetScheme("https") - } - - for hKey, hValue := range g.Headers { - req.Header.Add(hKey, hValue) - } + g.setupRequest(method, req) for _, param := range params { param.Apply(&req.Header, uri.QueryArgs()) } @@ -92,6 +82,27 @@ func (g *HTTPClient) doQuery(method string, v easyjson.Unmarshaler, params ...Qu return } +// setupRequest does the necessary initial configuration to the http request +func (g *HTTPClient) setupRequest(path string, req *fasthttp.Request) { + + uri := req.URI() + + scheme := "http" + if g.Secured { + scheme = "https" + } + + uri.SetHost(g.Addr) + uri.SetPath(path) + uri.SetScheme(scheme) + + uri.QueryArgs().Add("key", g.ContentKey) + + for hKey, hValue := range g.Headers { + req.Header.Add(hKey, hValue) + } +} + // GetPageBySlug returns the only one page using slug filter func (g *HTTPClient) GetPageBySlug(slug string) (pages *Pages, err error) {