minor refactoring

This commit is contained in:
Miroslav Stampar 2011-03-11 20:16:34 +00:00
parent 2fd3f0d7b2
commit e64f225e65
3 changed files with 15 additions and 8 deletions

View File

@ -42,6 +42,7 @@ from lib.core.data import logger
from lib.core.data import paths
from lib.core.datatype import advancedDict
from lib.core.datatype import injectionDict
from lib.core.enums import HTTPHEADER
from lib.core.enums import HTTPMETHOD
from lib.core.enums import NULLCONNECTION
from lib.core.enums import PAYLOAD
@ -763,15 +764,15 @@ def checkNullConnection():
try:
page, headers = Request.getPage(method=HTTPMETHOD.HEAD)
if not page and 'Content-Length' in headers:
if not page and HTTPHEADER.CONTENT_LENGTH in headers:
kb.nullConnection = NULLCONNECTION.HEAD
infoMsg = "NULL connection is supported with HEAD header"
logger.info(infoMsg)
else:
page, headers = Request.getPage(auxHeaders={"Range": "bytes=-1"})
page, headers = Request.getPage(auxHeaders={HTTPHEADER.RANGE: "bytes=-1"})
if page and len(page) == 1 and 'Content-Range' in headers:
if page and len(page) == 1 and HTTPHEADER.CONTENT_RANGE in headers:
kb.nullConnection = NULLCONNECTION.RANGE
infoMsg = "NULL connection is supported with GET header "

View File

@ -63,6 +63,11 @@ class HASH:
MD5_GENERIC = r'(?i)\A[0-9a-f]{32}\Z'
SHA1_GENERIC = r'(?i)\A[0-9a-f]{40}\Z'
class HTTPHEADER:
RANGE = "Range"
CONTENT_LENGTH = "Content-Length"
CONTENT_RANGE = "Content-Range"
class EXPECTED:
BOOL = "bool"
INT = "int"

View File

@ -36,6 +36,7 @@ from lib.core.common import urlEncodeCookieValues
from lib.core.data import conf
from lib.core.data import kb
from lib.core.data import logger
from lib.core.enums import HTTPHEADER
from lib.core.enums import HTTPMETHOD
from lib.core.enums import NULLCONNECTION
from lib.core.enums import PLACE
@ -472,14 +473,14 @@ class Connect:
if not auxHeaders:
auxHeaders = {}
auxHeaders["Range"] = "bytes=-1"
auxHeaders[HTTPHEADER.RANGE] = "bytes=-1"
_, headers = Connect.getPage(url=uri, get=get, post=post, cookie=cookie, ua=ua, referer=referer, silent=silent, method=method, auxHeaders=auxHeaders, raise404=raise404)
if kb.nullConnection == NULLCONNECTION.HEAD and 'Content-Length' in headers:
pageLength = int(headers['Content-Length'])
elif kb.nullConnection == NULLCONNECTION.RANGE and 'Content-Range' in headers:
pageLength = int(headers['Content-Range'][headers['Content-Range'].find('/') + 1:])
if kb.nullConnection == NULLCONNECTION.HEAD and HTTPHEADER.CONTENT_LENGTH in headers:
pageLength = int(headers[HTTPHEADER.CONTENT_LENGTH])
elif kb.nullConnection == NULLCONNECTION.RANGE and HTTPHEADER.CONTENT_RANGE in headers:
pageLength = int(headers[HTTPHEADER.CONTENT_RANGE][headers[HTTPHEADER.CONTENT_RANGE].find('/') + 1:])
if not pageLength:
page, headers = Connect.getPage(url=uri, get=get, post=post, cookie=cookie, ua=ua, referer=referer, silent=silent, method=method, auxHeaders=auxHeaders, response=response, raise404=raise404, ignoreTimeout=timeBasedCompare)