Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
dmlib
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
domotika
dmlib
Commits
761f31bf
Commit
761f31bf
authored
8 years ago
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add expect 100 feature to the web client
parent
8b1d0a8e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
6 deletions
+65
-6
webutils.py
dmlib/utils/webutils.py
+65
-6
No files found.
dmlib/utils/webutils.py
View file @
761f31bf
...
...
@@ -74,10 +74,14 @@ class HTTPPageGetter(client.HTTPPageGetter):
rectimeout
=
15
checkTimeout
=
False
expect100
=
False
def
sendCommand
(
self
,
command
,
path
):
version
=
b
' HTTP/1.0
\r\n
'
if
self
.
expect100
:
version
=
b
' HTTP/1.1
\r\n
'
self
.
transport
.
writeSequence
([
command
,
b
' '
,
path
,
version
])
# XXX Serve per farlo diventare 1.1??
#def sendCommand(self, command, path):
# self.transport.write('%s %s HTTP/1.1\r\n' % (command, path))
def
lineReceived
(
self
,
*
args
,
**
kwargs
):
self
.
lastrec
=
time
.
time
()
...
...
@@ -100,9 +104,45 @@ class HTTPPageGetter(client.HTTPPageGetter):
auth
=
"Basic "
+
base64
.
encodestring
(
cred
)
.
replace
(
'
\012
'
,
''
)
#self.sendHeader('Authorization', auth)
self
.
factory
.
headers
[
'Authorization'
]
=
auth
if
self
.
expect100
:
self
.
factory
.
headers
[
'Expect'
]
=
'100-continue'
self
.
checkTimeout
=
task
.
LoopingCall
(
self
.
timeoutCheck
)
self
.
checkTimeout
.
start
(
1
)
return
client
.
HTTPPageGetter
.
connectionMade
(
self
,
*
args
,
**
kwargs
)
method
=
getattr
(
self
.
factory
,
'method'
,
b
'GET'
)
self
.
sendCommand
(
method
,
self
.
factory
.
path
)
if
self
.
factory
.
scheme
==
b
'http'
and
self
.
factory
.
port
!=
80
:
host
=
self
.
factory
.
host
+
b
':'
+
intToBytes
(
self
.
factory
.
port
)
elif
self
.
factory
.
scheme
==
b
'https'
and
self
.
factory
.
port
!=
443
:
host
=
self
.
factory
.
host
+
b
':'
+
intToBytes
(
self
.
factory
.
port
)
else
:
host
=
self
.
factory
.
host
self
.
sendHeader
(
b
'Host'
,
self
.
factory
.
headers
.
get
(
b
"host"
,
host
))
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
=
[]
for
(
key
,
value
)
in
self
.
factory
.
headers
.
items
():
if
key
.
lower
()
not
in
self
.
_specialHeaders
:
# we calculated it on our own
self
.
sendHeader
(
key
,
value
)
if
key
.
lower
()
==
b
'cookie'
:
cookieData
.
append
(
value
)
for
cookie
,
cookval
in
self
.
factory
.
cookies
.
items
():
cookieData
.
append
(
cookie
+
b
'='
+
cookval
)
if
cookieData
:
self
.
sendHeader
(
b
'Cookie'
,
b
'; '
.
join
(
cookieData
))
self
.
endHeaders
()
self
.
headers
=
{}
if
not
self
.
expect100
:
self
.
_writeData
()
def
_writeData
(
self
):
data
=
getattr
(
self
.
factory
,
'postdata'
,
None
)
if
data
is
not
None
:
self
.
transport
.
write
(
data
)
def
timeoutCheck
(
self
):
...
...
@@ -121,6 +161,12 @@ class HTTPPageGetter(client.HTTPPageGetter):
except
:
pass
def
handleStatus_100
(
self
):
if
self
.
expect100
:
self
.
_writeData
()
else
:
self
.
handleStatus_400
()
def
handleStatus_404
(
self
):
self
.
handleStatusDefault
()
self
.
factory
.
noPage
(
...
...
@@ -231,8 +277,8 @@ class HTTPPageGetterProgressStream(HTTPPageGetterProgress):
class
HTTPClientFactory
(
client
.
HTTPClientFactory
):
protocol
=
HTTPPageGetter
def
__init__
(
self
,
url
,
method
=
'GET'
,
postdata
=
None
,
headers
=
None
,
agent
=
"
Domotika Client (http://www.unixmedia.i
t)"
,
timeout
=
0
,
cookies
=
None
,
followRedirect
=
1
,
proxy_host
=
None
,
proxy_port
=
80
,
headerscb
=
None
):
agent
=
"
Nexlab Client (https://www.nexlab.ne
t)"
,
timeout
=
0
,
cookies
=
None
,
followRedirect
=
1
,
proxy_host
=
None
,
proxy_port
=
80
,
headerscb
=
None
,
expect100
=
False
):
if
proxy_host
:
self
.
has_proxy
=
True
else
:
...
...
@@ -241,6 +287,7 @@ class HTTPClientFactory(client.HTTPClientFactory):
self
.
proxy_port
=
proxy_port
self
.
myurl
=
url
self
.
headerscb
=
headerscb
self
.
expect100
=
expect100
client
.
HTTPClientFactory
.
__init__
(
self
,
url
,
method
,
postdata
,
headers
,
agent
,
timeout
,
cookies
,
followRedirect
)
...
...
@@ -271,6 +318,18 @@ class HTTPClientFactory(client.HTTPClientFactory):
self
.
headerscb
(
headers
)
return
client
.
HTTPClientFactory
.
gotHeaders
(
self
,
headers
)
def
buildProtocol
(
self
,
addr
):
p
=
protocol
.
ClientFactory
.
buildProtocol
(
self
,
addr
)
p
.
followRedirect
=
self
.
followRedirect
p
.
afterFoundGet
=
self
.
afterFoundGet
p
.
expect100
=
self
.
expect100
if
self
.
timeout
:
timeoutCall
=
reactor
.
callLater
(
self
.
timeout
,
p
.
timeout
)
self
.
deferred
.
addBoth
(
self
.
_cancelTimeout
,
timeoutCall
)
return
p
class
HTTPClientFactoryProgress
(
HTTPClientFactory
):
...
...
This diff is collapsed.
Click to expand it.
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