|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +$Id$ |
| 5 | +
|
| 6 | +This file is part of the sqlmap project, http://sqlmap.sourceforge.net. |
| 7 | +
|
| 8 | +Copyright (c) 2007-2010 Bernardo Damele A. G. <[email protected]> |
| 9 | +Copyright (c) 2006 Daniele Bellucci <[email protected]> |
| 10 | +
|
| 11 | +sqlmap is free software; you can redistribute it and/or modify it under |
| 12 | +the terms of the GNU General Public License as published by the Free |
| 13 | +Software Foundation version 2 of the License. |
| 14 | +
|
| 15 | +sqlmap is distributed in the hope that it will be useful, but WITHOUT ANY |
| 16 | +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 17 | +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 18 | +details. |
| 19 | +
|
| 20 | +You should have received a copy of the GNU General Public License along |
| 21 | +with sqlmap; if not, write to the Free Software Foundation, Inc., 51 |
| 22 | +Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | +""" |
| 24 | + |
| 25 | +import urllib2 |
| 26 | + |
| 27 | +class SmartRedirectHandler(urllib2.HTTPRedirectHandler): |
| 28 | + def http_error_301(self, req, fp, code, msg, headers): |
| 29 | + result = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers) |
| 30 | + |
| 31 | + if "location" in headers: |
| 32 | + result.redurl = headers.getheaders("location")[0].split("?")[0] |
| 33 | + elif "uri" in headers: |
| 34 | + result.redurl = headers.getheaders("uri")[0].split("?")[0] |
| 35 | + |
| 36 | + return result |
| 37 | + |
| 38 | + def http_error_302(self, req, fp, code, msg, headers): |
| 39 | + result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers) |
| 40 | + |
| 41 | + if "location" in headers: |
| 42 | + result.redurl = headers.getheaders("location")[0].split("?")[0] |
| 43 | + elif "uri" in headers: |
| 44 | + result.redurl = headers.getheaders("uri")[0].split("?")[0] |
| 45 | + |
| 46 | + return result |
0 commit comments