File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -346,8 +346,10 @@ def getXMLTree(rsp: ResponseWrapper) -> etree:
346
346
content_type = rsp .info ().get ('Content-Type' , 'text/xml' )
347
347
url = rsp .geturl ()
348
348
349
+ has_xml_tag = raw_text .lstrip ().startswith (b'<?xml' )
350
+
349
351
xml_types = ['text/xml' , 'application/xml' , 'application/vnd.ogc.wms_xml' ]
350
- if not any (xt in content_type .lower () for xt in xml_types ):
352
+ if not any (xt in content_type .lower () for xt in xml_types ) and not has_xml_tag :
351
353
html_body = et .find ('BODY' ) # note this is case-sensitive
352
354
if html_body is not None and len (html_body .text ) > 0 :
353
355
response_text = html_body .text .strip ("\n " )
Original file line number Diff line number Diff line change @@ -71,6 +71,20 @@ def test_getXMLTree_valid():
71
71
assert et .find ('.//Title' ).text == "Example"
72
72
73
73
74
+ def test_getXMLTree_non_xml_mime_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
+ # test with a non-XML mime type, but the response starts with <?xml
81
+ mock_resp .headers = {'Content-Type' : 'application/octet-stream' }
82
+ resp_wrap = ResponseWrapper (mock_resp )
83
+
84
+ et = getXMLTree (resp_wrap )
85
+ assert et .find ('.//Title' ).text == "Example"
86
+
87
+
74
88
def test_getXMLTree_valid_missing_content_type ():
75
89
76
90
mock_resp = mock .Mock ()
You can’t perform that action at this time.
0 commit comments