simplified the controller code to make use of the new request headers object

This commit is contained in:
Gonçalo Valério 2019-04-03 23:17:02 +01:00
parent 5c2a29a21a
commit e835a99b43
3 changed files with 8 additions and 15 deletions

View File

@ -70,9 +70,9 @@
<th>Content</th> <th>Content</th>
</thead> </thead>
<tbody> <tbody>
<tr v-for="header in request.headers"> <tr v-for="(value, header) in request.headers">
<td>[[header.name]]</td> <td>[[header]]</td>
<td>[[header.value]]</td> <td>[[value]]</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -51,17 +51,10 @@ class CallbackView(View):
"ip_address": get_ip_address(request), "ip_address": get_ip_address(request),
"query_params": request.GET, "query_params": request.GET,
"body": body, "body": body,
"headers": self._received_headers(), "headers": self._filter_headers(request.headers),
"received_at": timezone.now().isoformat(), "received_at": timezone.now().isoformat(),
} }
def _received_headers(self): def _filter_headers(self, headers):
request = self.request exc = settings.EXCLUDED_HEADERS
headers = [] return {key: value for key, value in headers.items() if key not in exc}
for key, value in request.META.items():
if key.startswith("HTTP") and key not in settings.EXCLUDED_HEADERS:
original_header = (
key.replace("HTTP_", "").replace("_", "-").capitalize()
)
headers.append({"name": original_header, "value": value})
return headers

View File

@ -116,4 +116,4 @@ CHANNEL_LAYERS = {
} }
# Should use the format of request.META # Should use the format of request.META
EXCLUDED_HEADERS = os.environ.get("EXCLUDE_HEADERS", "").split(",") EXCLUDED_HEADERS = os.environ.get("EXCLUDED_HEADERS", "").split(",")