Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Network Health
sbws
Commits
7022ff30
Commit
7022ff30
authored
Dec 12, 2018
by
juga
Browse files
scanner: refactor, move HTTP headers to constants
parent
106e8a97
Changes
2
Hide whitespace changes
Inline
Side-by-side
sbws/core/scanner.py
View file @
7022ff30
...
...
@@ -9,7 +9,7 @@ from ..lib.relayprioritizer import RelayPrioritizer
from
..lib.destination
import
DestinationList
from
..util.timestamp
import
now_isodt_str
from
..util.state
import
State
from
sbws.globals
import
fail_hard
from
sbws.globals
import
fail_hard
,
HTTP_GET_HEADERS
import
sbws.util.stem
as
stem_utils
import
sbws.util.requests
as
requests_utils
from
argparse
import
ArgumentDefaultsHelpFormatter
...
...
@@ -31,14 +31,15 @@ def timed_recv_from_server(session, dest, byte_range):
''' Request the **byte_range** from the URL at **dest**. If successful,
return True and the time it took to download. Otherwise return False and an
exception. '''
headers
=
{
'Range'
:
byte_range
,
'Accept-Encoding'
:
'identity'
}
start_time
=
time
.
time
()
HTTP_GET_HEADERS
[
'Range'
]
=
byte_range
# TODO:
# - What other exceptions can this throw?
# - Do we have to read the content, or did requests already do so?
try
:
# headers are merged with the session ones, not overwritten.
session
.
get
(
dest
.
url
,
headers
=
headers
,
verify
=
dest
.
verify
)
session
.
get
(
dest
.
url
,
headers
=
HTTP_GET_HEADERS
,
verify
=
dest
.
verify
)
except
requests
.
exceptions
.
ConnectionError
as
e
:
return
False
,
e
except
requests
.
exceptions
.
ReadTimeout
as
e
:
...
...
sbws/globals.py
View file @
7022ff30
...
...
@@ -53,6 +53,11 @@ MAX_BW_DIFF_PERC = 50
BW_LINE_SIZE
=
510
HTTP_GET_HEADERS
=
{
'Range'
:
'{}'
,
'Accept-Encoding'
:
'identity'
,
}
def
fail_hard
(
*
a
,
**
kw
):
''' Log something ... and then exit as fast as possible '''
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment