kopia lustrzana https://github.com/snarfed/bridgy-fed
webmention: handle missing Content-Type header
for https://console.cloud.google.com/errors/CNnflKqP5rHWvgE , https://console.cloud.google.com/errors/CPyMpaulkMKWZAthib
rodzic
bddab29420
commit
2a91f01393
|
@ -1 +1 @@
|
|||
local3/lib/python3.6/site-packages/oauth_dropins
|
||||
../oauth-dropins/oauth_dropins
|
|
@ -7,5 +7,6 @@ feedparser~=5.2
|
|||
google-cloud-logging~=1.14
|
||||
gunicorn~=20.0
|
||||
mf2util~=0.5.0
|
||||
mox3~=0.28
|
||||
pycrypto~=2.6
|
||||
requests~=2.22
|
||||
|
|
|
@ -153,7 +153,6 @@ class WebmentionTest(testutil.TestCase):
|
|||
'url': 'https://foo.com/about-me',
|
||||
'inbox': 'https://foo.com/inbox',
|
||||
}, content_type=CONTENT_TYPE_AS2)
|
||||
self.activitypub_gets = [self.reply, self.orig_as2, self.actor]
|
||||
|
||||
self.as2_create = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
|
@ -217,14 +216,6 @@ class WebmentionTest(testutil.TestCase):
|
|||
'cc': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
}
|
||||
|
||||
self.actor = requests_response({
|
||||
'objectType' : 'person',
|
||||
'displayName': 'Mrs. ☕ Foo',
|
||||
'url': 'https://foo.com/about-me',
|
||||
'inbox': 'https://foo.com/inbox',
|
||||
}, content_type=CONTENT_TYPE_AS2)
|
||||
self.activitypub_gets = [self.reply, self.orig_as2, self.actor]
|
||||
|
||||
self.create_html = """\
|
||||
<html>
|
||||
<body class="h-entry">
|
||||
|
@ -259,12 +250,6 @@ class WebmentionTest(testutil.TestCase):
|
|||
},
|
||||
}
|
||||
|
||||
self.actor = requests_response({
|
||||
'objectType' : 'person',
|
||||
'displayName': 'Mrs. ☕ Foo',
|
||||
'url': 'https://foo.com/about-me',
|
||||
'inbox': 'https://foo.com/inbox',
|
||||
}, content_type=CONTENT_TYPE_AS2)
|
||||
self.activitypub_gets = [self.reply, self.orig_as2, self.actor]
|
||||
|
||||
def verify_salmon(self, mock_post):
|
||||
|
@ -343,6 +328,16 @@ class WebmentionTest(testutil.TestCase):
|
|||
body=urlencode({'source': 'http://a/post'}).encode())
|
||||
self.assertEqual(502, got.status_int)
|
||||
|
||||
def test_target_fetch_has_no_content_type(self, mock_get, mock_post):
|
||||
mock_get.side_effect = (
|
||||
requests_response(self.reply_html),
|
||||
requests_response(self.reply_html, content_type='None')
|
||||
)
|
||||
got = application.get_response(
|
||||
'/webmention', method='POST',
|
||||
body=urlencode({'source': 'http://a/post'}).encode())
|
||||
self.assertEqual(502, got.status_int)
|
||||
|
||||
def test_no_backlink(self, mock_get, mock_post):
|
||||
mock_get.return_value = requests_response(
|
||||
self.reply_html.replace('<a href="http://localhost/"></a>', ''),
|
||||
|
|
|
@ -162,12 +162,12 @@ class WebmentionHandler(common.Handler):
|
|||
self.target_resp = common.get_as2(target)
|
||||
except (requests.HTTPError, exc.HTTPBadGateway) as e:
|
||||
self.target_resp = getattr(e, 'response', None)
|
||||
if (self.target_resp and self.target_resp.status_code // 100 == 2 and
|
||||
common.content_type(self.target_resp).startswith('text/html')):
|
||||
# TODO: pass e.response to try_salmon()'s target_resp
|
||||
return False # make post() try Salmon
|
||||
else:
|
||||
raise
|
||||
if self.target_resp and self.target_resp.status_code // 100 == 2:
|
||||
content_type = common.content_type(self.target_resp) or ''
|
||||
if content_type.startswith('text/html'):
|
||||
# TODO: pass e.response to try_salmon()'s target_resp
|
||||
return False # make post() try Salmon
|
||||
raise
|
||||
target_url = self.target_resp.url or target
|
||||
|
||||
resp = Response.get_or_create(
|
||||
|
|
Ładowanie…
Reference in New Issue