From e64f225e65d1eee8aa3e5b5614dcd7464f0c3506 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Fri, 11 Mar 2011 20:16:34 +0000 Subject: [PATCH] minor refactoring --- lib/controller/checks.py | 7 ++++--- lib/core/enums.py | 5 +++++ lib/request/connect.py | 11 ++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/controller/checks.py b/lib/controller/checks.py index 8d53ad081..5342be1d3 100644 --- a/lib/controller/checks.py +++ b/lib/controller/checks.py @@ -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 " diff --git a/lib/core/enums.py b/lib/core/enums.py index a025fae26..c3686f793 100644 --- a/lib/core/enums.py +++ b/lib/core/enums.py @@ -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" diff --git a/lib/request/connect.py b/lib/request/connect.py index b796c6eba..45ae3f7fa 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -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)