Skip to content
Snippets Groups Projects
Commit 1033633c authored by Pavel Kácha's avatar Pavel Kácha
Browse files

- Apache times out connection, but httplib does not signal that

  consistently. Possible keeping and reopening where possible will need more
  work and testing, I'm not keen to try to clench in now. So - changed to
  reopening connection each time, which will possibly affect performance (on
  small queries).
- Both server and client library now defaults to get_events_limit instead of 1
parent 9440417a
No related branches found
No related tags found
No related merge requests found
...@@ -226,8 +226,9 @@ class Client(object): ...@@ -226,8 +226,9 @@ class Client(object):
try: try:
if self.url.scheme=="https": if self.url.scheme=="https":
self.conn = HTTPSConnection( conn = HTTPSConnection(
self.url.netloc, self.url.netloc,
strict = False,
key_file = self.keyfile, key_file = self.keyfile,
cert_file = self.certfile, cert_file = self.certfile,
timeout = self.timeout, timeout = self.timeout,
...@@ -235,8 +236,9 @@ class Client(object): ...@@ -235,8 +236,9 @@ class Client(object):
ca_certs = self.cafile, ca_certs = self.cafile,
ssl_version = self.sslversion) ssl_version = self.sslversion)
elif self.url.scheme=="http": elif self.url.scheme=="http":
self.conn = httplib.HTTPConnection( conn = httplib.HTTPConnection(
self.url.netloc, self.url.netloc,
strict = False,
timeout = self.timeout) timeout = self.timeout)
else: else:
return Error("Don't know how to connect to \"%s\"" % self.url.scheme, self.logger, return Error("Don't know how to connect to \"%s\"" % self.url.scheme, self.logger,
...@@ -252,7 +254,7 @@ class Client(object): ...@@ -252,7 +254,7 @@ class Client(object):
"ciphers": self.ciphers, "ciphers": self.ciphers,
"ssl_version": self.sslversion}) "ssl_version": self.sslversion})
return True return conn
def sendRequest(self, func="", payload=None, **kwargs): def sendRequest(self, func="", payload=None, **kwargs):
...@@ -285,19 +287,16 @@ class Client(object): ...@@ -285,19 +287,16 @@ class Client(object):
"Content-Length": str(len(data)) "Content-Length": str(len(data))
} }
# We are connecting here at first use instead of in # HTTP(S)Connection is oneshot object (and we don't speak "pipelining")
# constructor, because constructor cannot return data/errors conn = self.connect()
# and we don't want to spit exceptions into user's face if not conn:
# And maaaybee sometime we will implement reconnection on errors return conn # either False of Error instance
if self.conn is None:
err = self.connect()
if not err:
return err # either False of Error instance
loc = '%s/%s%s' % (self.url.path, func, argurl) loc = '%s/%s%s' % (self.url.path, func, argurl)
try: try:
self.conn.request("POST", loc, data, self.headers) conn.request("POST", loc, data, self.headers)
except: except:
conn.close()
return Error("Sending of request to server failed", self.logger, return Error("Sending of request to server failed", self.logger,
exc=exc_info(), method=func, detail={ exc=exc_info(), method=func, detail={
"loc": loc, "loc": loc,
...@@ -305,14 +304,24 @@ class Client(object): ...@@ -305,14 +304,24 @@ class Client(object):
"data": data}) "data": data})
try: try:
res = self.conn.getresponse() res = conn.getresponse()
except: except:
return Error("HTTP reply failed", self.logger, method=func, exc=exc_info()) conn.close()
return Error("HTTP reply failed", self.logger, method=func, exc=exc_info(), detail={
"loc": loc,
"headers": self.headers,
"data": data})
try: try:
response_data = res.read() response_data = res.read()
except: except:
return Error("Fetching HTTP data from server failed", self.logger, method=func, exc=exc_info()) conn.close()
return Error("Fetching HTTP data from server failed", self.logger, method=func, exc=exc_info(), detail={
"loc": loc,
"headers": self.headers,
"data": data})
conn.close()
if res.status==httplib.OK: if res.status==httplib.OK:
try: try:
...@@ -382,7 +391,7 @@ class Client(object): ...@@ -382,7 +391,7 @@ class Client(object):
return res return res
def getEvents(self, id=None, idstore=None, count=1, def getEvents(self, id=None, idstore=None, count=None,
cat=None, nocat=None, cat=None, nocat=None,
tag=None, notag=None, tag=None, notag=None,
group=None, nogroup=None): group=None, nogroup=None):
......
...@@ -794,7 +794,7 @@ class WardenHandler(ObjectReq): ...@@ -794,7 +794,7 @@ class WardenHandler(ObjectReq):
try: try:
count = int(count[0]) count = int(count[0])
except (ValueError, TypeError, IndexError): except (ValueError, TypeError, IndexError):
count = 1 count = self.get_events_limit
if self.get_events_limit: if self.get_events_limit:
count = min(count, self.get_events_limit) count = min(count, self.get_events_limit)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment