Skip to content

Commit

Permalink
checking XML formatted from HTTP response #39
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengchun committed Aug 30, 2020
1 parent 64ca73d commit 5648b2f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

1 comment on commit 5648b2f

@mclane
Copy link

@mclane mclane commented on 5648b2f Nov 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents other xml like formats (e.g. Google KML / KMZ) to be handeled by this function. It would be nice to either open it up for other xml dialects or introduce a parameter to specify them.

Please sign in to comment.