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):
try:
if self.url.scheme=="https":
self.conn = HTTPSConnection(
conn = HTTPSConnection(
self.url.netloc,
strict = False,
key_file = self.keyfile,
cert_file = self.certfile,
timeout = self.timeout,
......@@ -235,8 +236,9 @@ class Client(object):
ca_certs = self.cafile,
ssl_version = self.sslversion)
elif self.url.scheme=="http":
self.conn = httplib.HTTPConnection(
conn = httplib.HTTPConnection(
self.url.netloc,
strict = False,
timeout = self.timeout)
else:
return Error("Don't know how to connect to \"%s\"" % self.url.scheme, self.logger,
......@@ -252,7 +254,7 @@ class Client(object):
"ciphers": self.ciphers,
"ssl_version": self.sslversion})
return True
return conn
def sendRequest(self, func="", payload=None, **kwargs):
......@@ -285,19 +287,16 @@ class Client(object):
"Content-Length": str(len(data))
}
# We are connecting here at first use instead of in
# constructor, because constructor cannot return data/errors
# and we don't want to spit exceptions into user's face
# And maaaybee sometime we will implement reconnection on errors
if self.conn is None:
err = self.connect()
if not err:
return err # either False of Error instance
# HTTP(S)Connection is oneshot object (and we don't speak "pipelining")
conn = self.connect()
if not conn:
return conn # either False of Error instance
loc = '%s/%s%s' % (self.url.path, func, argurl)
try:
self.conn.request("POST", loc, data, self.headers)
conn.request("POST", loc, data, self.headers)
except:
conn.close()
return Error("Sending of request to server failed", self.logger,
exc=exc_info(), method=func, detail={
"loc": loc,
......@@ -305,14 +304,24 @@ class Client(object):
"data": data})
try:
res = self.conn.getresponse()
res = conn.getresponse()
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:
response_data = res.read()
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:
try:
......@@ -382,7 +391,7 @@ class Client(object):
return res
def getEvents(self, id=None, idstore=None, count=1,
def getEvents(self, id=None, idstore=None, count=None,
cat=None, nocat=None,
tag=None, notag=None,
group=None, nogroup=None):
......
......@@ -794,7 +794,7 @@ class WardenHandler(ObjectReq):
try:
count = int(count[0])
except (ValueError, TypeError, IndexError):
count = 1
count = self.get_events_limit
if 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