From 5648b2f39e8d5d3fc903c45a4f1274829df71821 Mon Sep 17 00:00:00 2001 From: zhengchun Date: Sun, 30 Aug 2020 21:32:47 +0800 Subject: [PATCH] checking XML formatted from HTTP response #39 --- parse.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/parse.go b/parse.go index 7b5cd66..32dfedc 100644 --- a/parse.go +++ b/parse.go @@ -19,7 +19,12 @@ func LoadURL(url string) (*Node, error) { return nil, err } defer resp.Body.Close() - return Parse(resp.Body) + // Checking the HTTP Content-Type value from the response headers.(#39) + v := strings.ToLower(resp.Header.Get("Content-Type")) + if v == "text/xml" || v == "application/xml" { + return Parse(resp.Body) + } + return nil, fmt.Errorf("invalid XML document(%s)", v) } // Parse returns the parse tree for the XML from the given Reader.