Skip to content

Commit 7ae09c7

Browse files
authored
Default to text/xml if server doesn't return a Content-Type (#977)
1 parent 39ad5a9 commit 7ae09c7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

owslib/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ def getXMLTree(rsp: ResponseWrapper) -> etree:
342342
et = etree.fromstring(raw_text)
343343

344344
# check for response type - if it is not xml then raise an error
345-
content_type = rsp.info()['Content-Type']
345+
# if the server doesn't provide a Content-Type then assume xml
346+
content_type = rsp.info().get('Content-Type', 'text/xml')
346347
url = rsp.geturl()
347348

348349
xml_types = ['text/xml', 'application/xml', 'application/vnd.ogc.wms_xml']

tests/test_util.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ def test_getXMLTree_valid():
7171
assert et.find('.//Title').text == "Example"
7272

7373

74+
def test_getXMLTree_valid_missing_content_type():
75+
76+
mock_resp = mock.Mock()
77+
mock_resp.url = 'http:///example.org/?service=WFS&request=GetCapabilities&version=2.0.0'
78+
mock_resp.content = b'<?xml version="1.0" encoding="UTF-8"?>\n<WFS_Capabilities><ServiceIdentification>' \
79+
b'<Title>Example</Title></ServiceIdentification></WFS_Capabilities>'
80+
mock_resp.headers = {}
81+
resp_wrap = ResponseWrapper(mock_resp)
82+
83+
et = getXMLTree(resp_wrap)
84+
assert et.find('.//Title').text == "Example"
85+
86+
7487
def test_getXMLTree_invalid():
7588

7689
mock_resp = mock.Mock()

0 commit comments

Comments
 (0)