Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
python-nexlibs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexlab
python-nexlibs
Commits
81384c5c
Commit
81384c5c
authored
Oct 26, 2016
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update webutils
parent
b461ab22
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
6 deletions
+28
-6
webutils.py
nexlibs/utils/webutils.py
+28
-6
No files found.
nexlibs/utils/webutils.py
View file @
81384c5c
...
@@ -73,6 +73,7 @@ class HTTPPageGetter(client.HTTPPageGetter):
...
@@ -73,6 +73,7 @@ class HTTPPageGetter(client.HTTPPageGetter):
rectimeout
=
15
rectimeout
=
15
checkTimeout
=
False
checkTimeout
=
False
expect100
=
False
expect100
=
False
received100
=
False
def
sendCommand
(
self
,
command
,
path
):
def
sendCommand
(
self
,
command
,
path
):
version
=
b
' HTTP/1.0
\r\n
'
version
=
b
' HTTP/1.0
\r\n
'
...
@@ -90,6 +91,7 @@ class HTTPPageGetter(client.HTTPPageGetter):
...
@@ -90,6 +91,7 @@ class HTTPPageGetter(client.HTTPPageGetter):
return
client
.
HTTPPageGetter
.
rawDataReceived
(
self
,
*
args
,
**
kwargs
)
return
client
.
HTTPPageGetter
.
rawDataReceived
(
self
,
*
args
,
**
kwargs
)
def
connectionMade
(
self
,
*
args
,
**
kwargs
):
def
connectionMade
(
self
,
*
args
,
**
kwargs
):
self
.
lastrec
=
time
.
time
()
self
.
lastrec
=
time
.
time
()
if
self
.
checkTimeout
:
if
self
.
checkTimeout
:
try
:
try
:
...
@@ -102,8 +104,6 @@ class HTTPPageGetter(client.HTTPPageGetter):
...
@@ -102,8 +104,6 @@ class HTTPPageGetter(client.HTTPPageGetter):
auth
=
"Basic "
+
base64
.
encodestring
(
cred
)
.
replace
(
'
\012
'
,
''
)
auth
=
"Basic "
+
base64
.
encodestring
(
cred
)
.
replace
(
'
\012
'
,
''
)
#self.sendHeader('Authorization', auth)
#self.sendHeader('Authorization', auth)
self
.
factory
.
headers
[
'Authorization'
]
=
auth
self
.
factory
.
headers
[
'Authorization'
]
=
auth
if
self
.
expect100
:
self
.
factory
.
headers
[
'Expect'
]
=
'100-continue'
self
.
checkTimeout
=
task
.
LoopingCall
(
self
.
timeoutCheck
)
self
.
checkTimeout
=
task
.
LoopingCall
(
self
.
timeoutCheck
)
self
.
checkTimeout
.
start
(
1
)
self
.
checkTimeout
.
start
(
1
)
method
=
getattr
(
self
.
factory
,
'method'
,
b
'GET'
)
method
=
getattr
(
self
.
factory
,
'method'
,
b
'GET'
)
...
@@ -116,21 +116,33 @@ class HTTPPageGetter(client.HTTPPageGetter):
...
@@ -116,21 +116,33 @@ class HTTPPageGetter(client.HTTPPageGetter):
host
=
self
.
factory
.
host
host
=
self
.
factory
.
host
self
.
sendHeader
(
b
'Host'
,
self
.
factory
.
headers
.
get
(
b
"host"
,
host
))
self
.
sendHeader
(
b
'Host'
,
self
.
factory
.
headers
.
get
(
b
"host"
,
host
))
self
.
sendHeader
(
b
'User-Agent'
,
self
.
factory
.
agent
)
self
.
sendHeader
(
b
'User-Agent'
,
self
.
factory
.
agent
)
data
=
getattr
(
self
.
factory
,
'postdata'
,
None
)
if
data
is
not
None
:
self
.
sendHeader
(
b
"Content-Length"
,
intToBytes
(
len
(
data
)))
cookieData
=
[]
cookieData
=
[]
contenttypehdr
=
False
for
(
key
,
value
)
in
self
.
factory
.
headers
.
items
():
for
(
key
,
value
)
in
self
.
factory
.
headers
.
items
():
if
key
.
lower
()
not
in
self
.
_specialHeaders
:
if
key
.
lower
()
not
in
self
.
_specialHeaders
:
# we calculated it on our own
# we calculated it on our own
self
.
sendHeader
(
key
,
value
)
if
key
.
lower
()
==
'content-type'
:
contenttypehdr
=
(
key
,
value
)
else
:
self
.
sendHeader
(
key
,
value
)
if
key
.
lower
()
==
b
'cookie'
:
if
key
.
lower
()
==
b
'cookie'
:
cookieData
.
append
(
value
)
cookieData
.
append
(
value
)
for
cookie
,
cookval
in
self
.
factory
.
cookies
.
items
():
for
cookie
,
cookval
in
self
.
factory
.
cookies
.
items
():
cookieData
.
append
(
cookie
+
b
'='
+
cookval
)
cookieData
.
append
(
cookie
+
b
'='
+
cookval
)
if
cookieData
:
if
cookieData
:
self
.
sendHeader
(
b
'Cookie'
,
b
'; '
.
join
(
cookieData
))
self
.
sendHeader
(
b
'Cookie'
,
b
'; '
.
join
(
cookieData
))
data
=
getattr
(
self
.
factory
,
'postdata'
,
None
)
if
data
is
not
None
:
self
.
sendHeader
(
b
"Content-Length"
,
intToBytes
(
len
(
data
)))
if
self
.
expect100
:
self
.
sendHeader
(
'Expect'
,
'100-continue'
)
if
contenttypehdr
:
key
,
value
=
contenttypehdr
self
.
sendHeader
(
key
,
value
)
self
.
endHeaders
()
self
.
endHeaders
()
self
.
headers
=
{}
self
.
headers
=
{}
...
@@ -159,11 +171,21 @@ class HTTPPageGetter(client.HTTPPageGetter):
...
@@ -159,11 +171,21 @@ class HTTPPageGetter(client.HTTPPageGetter):
except
:
except
:
pass
pass
def
lineReceived
(
self
,
line
):
client
.
HTTPPageGetter
.
lineReceived
(
self
,
line
)
if
self
.
expect100
and
self
.
received100
:
self
.
received100
=
False
self
.
setLineMode
()
def
handleStatus_100
(
self
):
def
handleStatus_100
(
self
):
self
.
received100
=
True
self
.
firstLine
=
True
self
.
__buffer
=
None
if
self
.
expect100
:
if
self
.
expect100
:
self
.
_writeData
()
self
.
_writeData
()
else
:
else
:
self
.
handleStatus_400
()
self
.
handleStatus_400
()
self
.
setLineMode
()
def
handleStatus_404
(
self
):
def
handleStatus_404
(
self
):
self
.
handleStatusDefault
()
self
.
handleStatusDefault
()
...
...
Write
Preview
Markdown
is supported
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