Skip to content

Commit 5648b2f

Browse files
committed
checking XML formatted from HTTP response #39
1 parent 64ca73d commit 5648b2f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

parse.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ func LoadURL(url string) (*Node, error) {
1919
return nil, err
2020
}
2121
defer resp.Body.Close()
22-
return Parse(resp.Body)
22+
// Checking the HTTP Content-Type value from the response headers.(#39)
23+
v := strings.ToLower(resp.Header.Get("Content-Type"))
24+
if v == "text/xml" || v == "application/xml" {
25+
return Parse(resp.Body)
26+
}
27+
return nil, fmt.Errorf("invalid XML document(%s)", v)
2328
}
2429

2530
// Parse returns the parse tree for the XML from the given Reader.

0 commit comments

Comments
 (0)