http.py (1295:f60a68728306) http.py (1296:77f76e7b800f)
1import re
2import time
3import json
4import socket
5import select
6from unit.main import TestUnit
7
8

--- 108 unchanged lines hidden (view full) ---

117 resp = self._resp_to_dict(resp)
118
119 headers = resp.get('headers')
120 if headers and headers.get('Transfer-Encoding') == 'chunked':
121 resp['body'] = self._parse_chunked_body(resp['body']).decode(
122 encoding
123 )
124
1import re
2import time
3import json
4import socket
5import select
6from unit.main import TestUnit
7
8

--- 108 unchanged lines hidden (view full) ---

117 resp = self._resp_to_dict(resp)
118
119 headers = resp.get('headers')
120 if headers and headers.get('Transfer-Encoding') == 'chunked':
121 resp['body'] = self._parse_chunked_body(resp['body']).decode(
122 encoding
123 )
124
125 if 'json' in kwargs:
126 resp = self._parse_json(resp)
127
125 if 'start' not in kwargs:
126 sock.close()
127 return resp
128
129 return (resp, sock)
130
131 def delete(self, **kwargs):
132 return self.http('DELETE', **kwargs)

--- 92 unchanged lines hidden (view full) ---

225 body += temp_body[:size]
226
227 temp_body = temp_body[size + len(crlf) :]
228
229 chunks = temp_body.split(crlf)
230
231 return body
232
128 if 'start' not in kwargs:
129 sock.close()
130 return resp
131
132 return (resp, sock)
133
134 def delete(self, **kwargs):
135 return self.http('DELETE', **kwargs)

--- 92 unchanged lines hidden (view full) ---

228 body += temp_body[:size]
229
230 temp_body = temp_body[size + len(crlf) :]
231
232 chunks = temp_body.split(crlf)
233
234 return body
235
236 def _parse_json(self, resp):
237 headers = resp['headers']
238
239 self.assertIn('Content-Type', headers, 'Content-Type header set')
240 self.assertEqual(
241 headers['Content-Type'],
242 'application/json',
243 'Content-Type header is application/json',
244 )
245
246 resp['body'] = json.loads(resp['body'])
247
248 return resp
249
250 def getjson(self, **kwargs):
251 return self.get(json=True, **kwargs)
252
233 def waitforsocket(self, port):
234 ret = False
235
236 for i in range(50):
237 try:
238 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
239 sock.connect(('127.0.0.1', port))
240 ret = True
241 break
242 except:
243 sock.close()
244 time.sleep(0.1)
245
246 sock.close()
247
248 self.assertTrue(ret, 'socket connected')
253 def waitforsocket(self, port):
254 ret = False
255
256 for i in range(50):
257 try:
258 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
259 sock.connect(('127.0.0.1', port))
260 ret = True
261 break
262 except:
263 sock.close()
264 time.sleep(0.1)
265
266 sock.close()
267
268 self.assertTrue(ret, 'socket connected')