From 3e23f7e872f519a01ce6a582ba4b5ec36f67a51a Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Fri, 26 Aug 2022 20:52:27 +0200 Subject: [PATCH] added check on Accept request header --- src/ws/page.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ws/page.go b/src/ws/page.go index a73fd61..f31cd1d 100644 --- a/src/ws/page.go +++ b/src/ws/page.go @@ -19,10 +19,15 @@ func (p *Page) GetContent(c echo.Context) (err error) { // Process returns main webpage or a JSON func (p *Page) Process(c echo.Context, querytype string) (err error) { p.GetContent(c) - if querytype != "json" { - return c.Render(http.StatusOK, "index.html", p) + if querytype == "json" { + return c.JSONPretty(http.StatusOK, p.IP, " ") } - return c.JSONPretty(http.StatusOK, p.IP, " ") + if accept, ok := c.Request().Header["Accept"]; ok { + if accept[0] == "*/*" { + return c.JSONPretty(http.StatusOK, p.IP, " ") + } + } + return c.Render(http.StatusOK, "index.html", p) } // Page defines Web page