Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb999de

Browse files
committed
added Range handler (dealing with 206 HTTP messages)
1 parent 875781b commit eb999de

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

lib/core/option.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@
6464
from lib.parse.configfile import configFileParser
6565
from lib.request.proxy import ProxyHTTPSHandler
6666
from lib.request.certhandler import HTTPSCertAuthHandler
67+
from lib.request.rangehandler import HTTPRangeHandler
6768
from lib.request.redirecthandler import SmartRedirectHandler
6869
from lib.utils.google import Google
6970

7071
authHandler = urllib2.BaseHandler()
7172
keepAliveHandler = keepalive.HTTPHandler()
7273
proxyHandler = urllib2.BaseHandler()
7374
redirectHandler = SmartRedirectHandler()
75+
rangeHandler = HTTPRangeHandler()
7476

7577
def __urllib2Opener():
7678
"""
@@ -80,12 +82,13 @@ def __urllib2Opener():
8082
global authHandler
8183
global keepAliveHandler
8284
global proxyHandler
85+
global rangeHandler
8386
global redirectHandler
8487

8588
debugMsg = "creating HTTP requests opener object"
8689
logger.debug(debugMsg)
8790

88-
handlers = [proxyHandler, authHandler, redirectHandler]
91+
handlers = [proxyHandler, authHandler, redirectHandler, rangeHandler]
8992

9093
if not conf.dropSetCookie:
9194
conf.cj = cookielib.LWPCookieJar()

lib/request/rangehandler.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
$Id$
5+
6+
Copyright (c) 2006-2010 sqlmap developers (http://sqlmap.sourceforge.net/)
7+
See the file 'doc/COPYING' for copying permission
8+
"""
9+
10+
import urllib
11+
import urllib2
12+
13+
from lib.core.exception import sqlmapConnectionException
14+
15+
class HTTPRangeHandler(urllib2.BaseHandler):
16+
"""
17+
Handler that enables HTTP Range headers.
18+
19+
Reference: http://stackoverflow.com/questions/1971240/python-seek-on-remote-file
20+
21+
This was extremely simple. The Range header is a HTTP feature to
22+
begin with so all this class does is tell urllib2 that the
23+
"206 Partial Content" reponse from the HTTP server is what we
24+
expected.
25+
26+
Example:
27+
import urllib2
28+
import byterange
29+
30+
range_handler = range.HTTPRangeHandler()
31+
opener = urllib2.build_opener(range_handler)
32+
33+
# install it
34+
urllib2.install_opener(opener)
35+
36+
# create Request and set Range header
37+
req = urllib2.Request('http://www.python.org/')
38+
req.header['Range'] = 'bytes=30-50'
39+
f = urllib2.urlopen(req)
40+
"""
41+
42+
def http_error_206(self, req, fp, code, msg, hdrs):
43+
# 206 Partial Content Response
44+
r = urllib.addinfourl(fp, hdrs, req.get_full_url())
45+
r.code = code
46+
r.msg = msg
47+
return r
48+
49+
def http_error_416(self, req, fp, code, msg, hdrs):
50+
# HTTP's Range Not Satisfiable error
51+
errMsg = "Invalid range"
52+
raise sqlmapConnectionException, errMsg

0 commit comments

Comments
 (0)