add space after Content-Length and Content-Type

ogAdmServer needs this space to work fine.
more_events
OpenGnSys Support Team 2020-01-27 21:22:39 +01:00 committed by Alvaro Neira Ayuso
parent 7196e7198e
commit f86999da0c
9 changed files with 36 additions and 36 deletions

View File

@ -50,8 +50,8 @@ class restResponse():
self.msg += '\r\n'
if jsonResp:
self.msg += 'Content-Length:' + str(len(jsonResp.dumpMsg()))
self.msg += '\r\nContent-Type:application/json'
self.msg += 'Content-Length: ' + str(len(jsonResp.dumpMsg()))
self.msg += '\r\nContent-Type: application/json'
self.msg += '\r\n\r\n' + jsonResp.dumpMsg()
else:
self.msg += '\r\n'

View File

@ -12,9 +12,9 @@ import sys
class Server():
_probe_json = '{"id": 0, "name": "test_local", "center": 0, "room": 0}'
_probe_msg = 'POST /probe HTTP/1.0\r\nContent-Length:'+ \
_probe_msg = 'POST /probe HTTP/1.0\r\nContent-Length: '+ \
str(len(_probe_json)) + \
'\r\nContent-Type:application/json\r\n\r\n' + _probe_json
'\r\nContent-Type: application/json\r\n\r\n' + _probe_json
_recv_buffer_size = 16384
def __init__(self, host='127.0.0.1', port=1234):

View File

@ -13,8 +13,8 @@ import unittest
class TestProbeMethods(unittest.TestCase):
def setUp(self):
self.ok_response = 'HTTP/1.0 200 OK\r\nContent-Length:17\r\n' \
'Content-Type:application/json\r\n\r\n' + \
self.ok_response = 'HTTP/1.0 200 OK\r\nContent-Length: 17\r\n' \
'Content-Type: application/json\r\n\r\n' + \
'{"status": "OPG"}'
def test_post(self):
@ -29,7 +29,7 @@ class TestProbeMethods(unittest.TestCase):
c = Client()
s = Server()
s.connect(probe=False)
s.send('POST /probe HTTP/1.0\r\nContent-Length:0\r\n\r\n')
s.send('POST /probe HTTP/1.0\r\nContent-Length: 0\r\n\r\n')
response = s.recv()
s.stop()
c.stop()
@ -38,8 +38,8 @@ class TestProbeMethods(unittest.TestCase):
def test_malformed_json(self):
json = '{"id": 0, "name": "test_local", "center": 0}'
len_json = str(len(json))
msg = 'POST /probe HTTP/1.0\r\nContent-Length:' + len_json + \
'\r\nContent-Type:application/json\r\n\r\n' + json
msg = 'POST /probe HTTP/1.0\r\nContent-Length: ' + len_json + \
'\r\nContent-Type: application/json\r\n\r\n' + json
c = Client()
s = Server()
s.connect(probe=False)
@ -64,8 +64,8 @@ class TestProbeMethods(unittest.TestCase):
json = '{"id": 0, "name": "test_local", "center": 0, "room": 0, ' + \
'"extra_param": true}'
len_json = str(len(json))
msg = 'POST /probe HTTP/1.0\r\nContent-Length:' + len_json + \
'\r\nContent-Type:application/json\r\n\r\n' + json
msg = 'POST /probe HTTP/1.0\r\nContent-Length: ' + len_json + \
'\r\nContent-Type: application/json\r\n\r\n' + json
c = Client()
s = Server()
s.connect(probe=False)

View File

@ -15,12 +15,12 @@ class TestShellRunMethods(unittest.TestCase):
def test_post_with_echo(self):
req_json = '{"run":"echo \\"croqueta\\"", "echo":true}'
response_json = '{"out": \"croqueta\\n\"}'
req = 'POST /shell/run HTTP/1.0\r\nContent-Length:'+ \
req = 'POST /shell/run HTTP/1.0\r\nContent-Length: '+ \
str(len(req_json)) + \
'\r\nContent-Type:application/json\r\n\r\n' + req_json
resp = 'HTTP/1.0 200 OK\r\nContent-Length:' + \
'\r\nContent-Type: application/json\r\n\r\n' + req_json
resp = 'HTTP/1.0 200 OK\r\nContent-Length: ' + \
str(len(response_json)) + \
'\r\nContent-Type:application/json\r\n\r\n' + response_json
'\r\nContent-Type: application/json\r\n\r\n' + response_json
c = Client()
s = Server()
s.connect()
@ -32,9 +32,9 @@ class TestShellRunMethods(unittest.TestCase):
def test_post_without_echo(self):
req_json = '{"run":"echo 1", "echo":false}'
req = 'POST /shell/run HTTP/1.0\r\nContent-Length:'+ \
req = 'POST /shell/run HTTP/1.0\r\nContent-Length: '+ \
str(len(req_json)) + \
'\r\nContent-Type:application/json\r\n\r\n' + req_json
'\r\nContent-Type: application/json\r\n\r\n' + req_json
resp = 'HTTP/1.0 200 OK\r\n\r\n'
c = Client()
s = Server()
@ -49,7 +49,7 @@ class TestShellRunMethods(unittest.TestCase):
c = Client()
s = Server()
s.connect()
s.send('POST /shell/run HTTP/1.0\r\nContent-Length:0\r\n\r\n')
s.send('POST /shell/run HTTP/1.0\r\nContent-Length: 0\r\n\r\n')
response = s.recv()
s.stop()
c.stop()
@ -58,8 +58,8 @@ class TestShellRunMethods(unittest.TestCase):
def test_malformed_json(self):
json = '{"wrong_param": 0}'
len_json = str(len(json))
msg = 'POST /shell/run HTTP/1.0\r\nContent-Length:' + len_json + \
'\r\nContent-Type:application/json\r\n\r\n' + json
msg = 'POST /shell/run HTTP/1.0\r\nContent-Length: ' + len_json + \
'\r\nContent-Type: application/json\r\n\r\n' + json
c = Client()
s = Server()
s.connect()
@ -71,17 +71,17 @@ class TestShellRunMethods(unittest.TestCase):
def test_serial_requests(self):
req1_json = '{"run":"echo 1", "echo":true}'
req1 = 'POST /shell/run HTTP/1.0\r\nContent-Length:'+ \
req1 = 'POST /shell/run HTTP/1.0\r\nContent-Length: '+ \
str(len(req1_json)) + \
'\r\nContent-Type:application/json\r\n\r\n' + req1_json
'\r\nContent-Type: application/json\r\n\r\n' + req1_json
req2_json = '{"run":"echo 2", "echo":true}'
req2 = 'POST /shell/run HTTP/1.0\r\nContent-Length:'+ \
req2 = 'POST /shell/run HTTP/1.0\r\nContent-Length: '+ \
str(len(req2_json)) + \
'\r\nContent-Type:application/json\r\n\r\n' + req2_json
'\r\nContent-Type: application/json\r\n\r\n' + req2_json
response_json = '{"out": "2\n"}'
resp = 'HTTP/1.0 200 OK\r\nContent-Length:' + \
resp = 'HTTP/1.0 200 OK\r\nContent-Length: ' + \
str(len(response_json)) + \
'\r\nContent-Type:application/json\r\n\r\n' + response_json
'\r\nContent-Type: application/json\r\n\r\n' + response_json
c = Client()
s = Server()
s.connect()

View File

@ -14,8 +14,8 @@ import json
class TestHardwareMethods(unittest.TestCase):
def test_get(self):
req = 'GET /hardware HTTP/1.0\r\nContent-Length:0\r\n' + \
'Content-Type:application/json\r\n\r\n '
req = 'GET /hardware HTTP/1.0\r\nContent-Length: 0\r\n' + \
'Content-Type: application/json\r\n\r\n '
c = Client()
s = Server()
s.connect()

View File

@ -14,9 +14,9 @@ class TestOtherRequests(unittest.TestCase):
def test_non_existent_function(self):
post_req = 'POST /this_function_does_not_exist HTTP/1.0\r\n' + \
'Content-Length:0\r\nContent-Type:application/json\r\n\r\n'
'Content-Length: 0\r\nContent-Type: application/json\r\n\r\n'
get_req = 'GET /this_function_does_not_exist HTTP/1.0\r\n' + \
'Content-Length:0\r\nContent-Type:application/json\r\n\r\n'
'Content-Length: 0\r\nContent-Type: application/json\r\n\r\n'
c = Client()
s = Server()
s.connect()

View File

@ -13,8 +13,8 @@ import unittest
class TestRunScheduleMethods(unittest.TestCase):
def test_get(self):
req = 'GET /run/schedule HTTP/1.0\r\nContent-Length:0'+ \
'\r\nContent-Type:application/json\r\n\r\n'
req = 'GET /run/schedule HTTP/1.0\r\nContent-Length: 0'+ \
'\r\nContent-Type: application/json\r\n\r\n'
c = Client()
s = Server()
s.connect()

View File

@ -15,9 +15,9 @@ class TestSoftwareMethods(unittest.TestCase):
def test_correct_post(self):
req_json = '{"disk": 1, "partition": 1}'
req = 'POST /software HTTP/1.0\r\nContent-Length:' + \
req = 'POST /software HTTP/1.0\r\nContent-Length: ' + \
str(len(req_json)) + \
'\r\nContent-Type:application/json\r\n\r\n' + req_json
'\r\nContent-Type: application/json\r\n\r\n' + req_json
c = Client()
s = Server()
s.connect()

View File

@ -14,8 +14,8 @@ import json
class TestRefreshMethods(unittest.TestCase):
def test_correct_get(self):
req = 'GET /refresh HTTP/1.0\r\nContent-Length:0\r\n' + \
'Content-Type:application/json\r\n\r\n'
req = 'GET /refresh HTTP/1.0\r\nContent-Length: 0\r\n' + \
'Content-Type: application/json\r\n\r\n'
c = Client()
s = Server()
s.connect()