Mercurial > p > roundup > code
comparison test/test_liveserver.py @ 6509:1fc765ef6379
Fix 204 responses, hangs and crashes with REST.
Remove Content-Type and make sure no content is returned by OPTIONS
request in REST interface.
In write_html set the Content-Length when response is not
encoded/compressed (fixes hang due to missing content-length with
unencoded data).
In REST interface do not raise UsageError for invalid api version.
Return json error with proper message. Fixes crash.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 16 Oct 2021 13:34:04 -0400 |
| parents | 3d2c17be1d35 |
| children | c505c774a94d |
comparison
equal
deleted
inserted
replaced
| 6507:bc95f7431efb | 6509:1fc765ef6379 |
|---|---|
| 111 headers = {'content-type': ""}) | 111 headers = {'content-type': ""}) |
| 112 print(f.status_code) | 112 print(f.status_code) |
| 113 print(f.headers) | 113 print(f.headers) |
| 114 | 114 |
| 115 self.assertEqual(f.status_code, 204) | 115 self.assertEqual(f.status_code, 204) |
| 116 expected = { 'Content-Type': 'application/json', | 116 expected = { 'Access-Control-Allow-Origin': '*', |
| 117 'Access-Control-Allow-Origin': '*', | |
| 118 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-HTTP-Method-Override', | 117 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-HTTP-Method-Override', |
| 119 'Allow': 'OPTIONS, GET', | 118 'Allow': 'OPTIONS, GET', |
| 120 'Access-Control-Allow-Methods': 'HEAD, OPTIONS, GET, PUT, DELETE, PATCH', | 119 'Access-Control-Allow-Methods': 'HEAD, OPTIONS, GET, PUT, DELETE, PATCH', |
| 121 } | 120 } |
| 122 | 121 |
| 132 ) | 131 ) |
| 133 print(f.status_code) | 132 print(f.status_code) |
| 134 print(f.headers) | 133 print(f.headers) |
| 135 | 134 |
| 136 self.assertEqual(f.status_code, 204) | 135 self.assertEqual(f.status_code, 204) |
| 137 expected = { 'Content-Type': 'application/json', | 136 expected = { 'Access-Control-Allow-Origin': '*', |
| 138 'Access-Control-Allow-Origin': '*', | |
| 139 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-HTTP-Method-Override', | 137 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-HTTP-Method-Override', |
| 140 'Allow': 'OPTIONS, GET', | 138 'Allow': 'OPTIONS, GET', |
| 141 'Access-Control-Allow-Methods': 'HEAD, OPTIONS, GET, PUT, DELETE, PATCH', | 139 'Access-Control-Allow-Methods': 'HEAD, OPTIONS, GET, PUT, DELETE, PATCH', |
| 142 } | 140 } |
| 143 | 141 |
| 152 headers = {'content-type': ""}) | 150 headers = {'content-type': ""}) |
| 153 print(f.status_code) | 151 print(f.status_code) |
| 154 print(f.headers) | 152 print(f.headers) |
| 155 | 153 |
| 156 self.assertEqual(f.status_code, 204) | 154 self.assertEqual(f.status_code, 204) |
| 157 expected = { 'Content-Type': 'application/json', | 155 expected = { 'Access-Control-Allow-Origin': '*', |
| 158 'Access-Control-Allow-Origin': '*', | |
| 159 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-HTTP-Method-Override', | 156 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-HTTP-Method-Override', |
| 160 'Allow': 'OPTIONS, GET, POST', | 157 'Allow': 'OPTIONS, GET, POST', |
| 161 'Access-Control-Allow-Methods': 'HEAD, OPTIONS, GET, PUT, DELETE, PATCH', | 158 'Access-Control-Allow-Methods': 'HEAD, OPTIONS, GET, PUT, DELETE, PATCH', |
| 162 } | 159 } |
| 163 | 160 |
| 173 headers = {'content-type': ""}) | 170 headers = {'content-type': ""}) |
| 174 print(f.status_code) | 171 print(f.status_code) |
| 175 print(f.headers) | 172 print(f.headers) |
| 176 | 173 |
| 177 self.assertEqual(f.status_code, 204) | 174 self.assertEqual(f.status_code, 204) |
| 178 expected = { 'Content-Type': 'application/json', | 175 expected = { 'Access-Control-Allow-Origin': '*', |
| 179 'Access-Control-Allow-Origin': '*', | |
| 180 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-HTTP-Method-Override', | 176 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-HTTP-Method-Override', |
| 181 'Allow': 'OPTIONS, GET, PUT, DELETE, PATCH', | 177 'Allow': 'OPTIONS, GET, PUT, DELETE, PATCH', |
| 182 'Access-Control-Allow-Methods': 'HEAD, OPTIONS, GET, PUT, DELETE, PATCH', | 178 'Access-Control-Allow-Methods': 'HEAD, OPTIONS, GET, PUT, DELETE, PATCH', |
| 183 } | 179 } |
| 184 | 180 |
| 193 headers = {'content-type': ""}) | 189 headers = {'content-type': ""}) |
| 194 print(f.status_code) | 190 print(f.status_code) |
| 195 print(f.headers) | 191 print(f.headers) |
| 196 | 192 |
| 197 self.assertEqual(f.status_code, 204) | 193 self.assertEqual(f.status_code, 204) |
| 198 expected = { 'Content-Type': 'application/json', | 194 expected = { 'Access-Control-Allow-Origin': '*', |
| 199 'Access-Control-Allow-Origin': '*', | |
| 200 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-HTTP-Method-Override', | 195 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-HTTP-Method-Override', |
| 201 'Allow': 'OPTIONS, GET, PUT, DELETE, PATCH', | 196 'Allow': 'OPTIONS, GET, PUT, DELETE, PATCH', |
| 202 'Access-Control-Allow-Methods': 'HEAD, OPTIONS, GET, PUT, DELETE, PATCH', | 197 'Access-Control-Allow-Methods': 'HEAD, OPTIONS, GET, PUT, DELETE, PATCH', |
| 203 } | 198 } |
| 204 | 199 |
