Skip to content

Commit d821f10

Browse files
committed
fix http data padding
1 parent f7ebeae commit d821f10

File tree

1 file changed

+5
-3
lines changed
  • prometheus_push_client/transports

1 file changed

+5
-3
lines changed

prometheus_push_client/transports/http.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ def _validate(self): # pragma: no cover
2121

2222
def prepare_data(self, iterable):
2323
data = b"\n".join(iterable)
24-
to_pad = sum(ord(b"\n") != char for char in data[-2:])
25-
return data.ljust(len(data) + to_pad, b"\n") # ensure ends with "\n\n"
24+
if data.endswith(b"\n\n"): # pragma: no cover
25+
return data
26+
to_pad = 1 if data[-1] == ord(b"\n") else 2
27+
return data.ljust(len(data) + to_pad, b"\n")
2628

2729
def push_all_sync(self):
2830
raise NotImplementedError("brave proposal")
@@ -41,7 +43,7 @@ def stop(self):
4143

4244
def push_all(self, iterable):
4345
data = self.prepare_data(iterable)
44-
resp = self.session.request(self.verb, self.url, data=data)
46+
self.session.request(self.verb, self.url, data=data)
4547

4648

4749
class AioHttpTransport(BaseHttpTransport):

0 commit comments

Comments
 (0)