Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial design #1

Closed
simonw opened this issue Aug 7, 2024 · 2 comments
Closed

Initial design #1

simonw opened this issue Aug 7, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Aug 7, 2024

This is a debugging tool. I want to make it easy to start iterating on things like webhooks or OAuth flows by configuring quick endpoints that return configured mock data and log the incoming request.

@simonw simonw added the enhancement New feature or request label Aug 7, 2024
@simonw
Copy link
Owner Author

simonw commented Aug 7, 2024

I got Claude 3.5 Sonnet to write most of the initial code:

I want a Django app I can use to help create HTTP debugging endpoints. It should let me configure a new path e.g. /webhooks/receive/ that the Django 404 handler then hooks into - if one is configured it can be told which HTTP status code, headers and content to return.

ALL traffic to those endpoints is logged to a Django table - full details of incoming request headers, method and body. Those can be browsed read-only in the Django admin (and deleted)

https://claude.site/artifacts/d7da92c2-8a6e-4fd8-a6f2-b243523af1b4

make it so I don't have to put it in the urlpatterns because it hooks ito Django's 404 handling mechanism instead

https://claude.site/artifacts/a1fb7996-e16b-403f-848c-e9ff0adcb9e3

Suggestions for how this could handle request bodies that don't cleanly decode to utf-8

https://claude.site/artifacts/9f1a2db7-d614-4fc0-9c84-860a2c1afa92

don't use a binary field, use a text field but still store base64 data in it if necessary and have a is_base64 boolean column that gets set to true if that happens

https://claude.site/artifacts/c49367b9-b6f9-4634-be72-a266e01579fd

@simonw
Copy link
Owner Author

simonw commented Aug 7, 2024

To get it to work correctly with DEBUG=True turned on I modified the middleware to work like this instead:

class DebugMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        response = self.get_response(request)
        if response.status_code == 404:
            path = request.path.lstrip("/")
            debug_response = debug_view(request, path)
            if debug_response:
                return debug_response
        return response

simonw added a commit that referenced this issue Aug 7, 2024
@simonw simonw closed this as completed Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant