mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-27 05:03:07 +01:00
Web: Add new @location command, to follow HTTP redirects.
Useful to un-tinify URLs.
This commit is contained in:
parent
d52e2aa829
commit
5195ff8e12
@ -275,6 +275,21 @@ class Web(callbacks.PluginRegexp):
|
||||
finally:
|
||||
fd.close()
|
||||
|
||||
@wrap(['httpUrl'])
|
||||
@catch_web_errors
|
||||
@fetch_sandbox
|
||||
def location(self, irc, msg, args, url):
|
||||
"""<url>
|
||||
|
||||
If the <url> is redirected to another page, returns the URL of that
|
||||
page. This works even if there are multiple redirects.
|
||||
Only HTTP urls are valid.
|
||||
Useful to "un-tinify" URLs."""
|
||||
timeout = self.registryValue('timeout')
|
||||
(target, text) = utils.web.getUrlTargetAndContent(url, size=60,
|
||||
timeout=timeout)
|
||||
irc.reply(target)
|
||||
|
||||
_doctypeRe = re.compile(r'(<!DOCTYPE[^>]+>)', re.M)
|
||||
@wrap(['httpUrl'])
|
||||
@catch_web_errors
|
||||
|
@ -37,6 +37,13 @@ class WebTestCase(ChannelPluginTestCase):
|
||||
self.assertError('headers ftp://ftp.cdrom.com/pub/linux')
|
||||
self.assertNotError('headers http://www.slashdot.org/')
|
||||
|
||||
def testLocation(self):
|
||||
self.assertError('location ftp://ftp.cdrom.com/pub/linux')
|
||||
self.assertResponse(
|
||||
'location http://limnoria.net/', 'https://limnoria.net/')
|
||||
self.assertResponse(
|
||||
'location https://www.limnoria.net/', 'https://limnoria.net/')
|
||||
|
||||
def testDoctype(self):
|
||||
self.assertError('doctype ftp://ftp.cdrom.com/pub/linux')
|
||||
self.assertNotError('doctype http://www.slashdot.org/')
|
||||
|
Loading…
Reference in New Issue
Block a user