Skip to content

fix(adapters): set explicit text/plain content type on blocked responses - #22

Merged
rennf93 merged 3 commits into
masterfrom
fix/block-response-content-type
Sep 25, 2026
Merged

rennf93 merged 3 commits into
masterfrom
fix/block-response-content-type

Conversation

@rennf93

@rennf93 rennf93 commented Sep 25, 2026

Copy link
Copy Markdown
Member

Summary

  • Blocked/error responses built by DjangoResponseFactory.create_response fell back to Django's default text/html; charset=utf-8. Under X-Content-Type-Options: nosniff (applied by default), that is exactly the gap fastapi-guard fixed in #144: the block page should be explicit text/plain.
  • create_response now passes content_type="text/plain; charset=utf-8". Redirect responses are untouched (no body, no content type).
  • Behavior beyond the default is preserved: custom_error_responses text stays text/plain, and a custom_response_modifier can still set its own content type.

Tests

  • New tests/test_block_response_content_type.py, mirroring fastapi-guard's test of the same name: block response is plain text with nosniff, custom error message stays plain text, modifier override wins.
  • Extended test_django_response_factory_create with the header assertion.
  • Full suite locally: 278 passed.

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 20c0c737-3451-4297-ab34-28e42b04bce9


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for opening your first pull request on djangoapi-guard!

Quick checklist before review (most of these are enforced by CI, but worth a glance):

  • make lint — ruff format, ruff check, mypy, and vulture
  • make test (or make local-test) — full test suite passes with 100% coverage
  • make security — bandit, safety, and pip-audit all clean
  • make quality — radon and xenon complexity thresholds respected
  • No # noqa / # type: ignore shortcuts; pre-existing violations in touched files are fixed
  • Added an entry under ## Unreleased in CHANGELOG.md
  • If you touched a public API, updated the relevant page under docs/
  • If the change involves engine logic, the corresponding fix landed in guard-core first

See CONTRIBUTING.md for the full workflow and the Code of Conduct for the community standards we follow.

Welcome aboard — a maintainer will review shortly.

@github-actions github-actions Bot added area: adapters Touches djangoapi_guard/adapters.py (request/response protocol implementations) tests Test suite changes labels Sep 25, 2026
@rennf93
rennf93 merged commit 0390131 into master Sep 25, 2026
12 checks passed
@rennf93
rennf93 deleted the fix/block-response-content-type branch September 27, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: adapters Touches djangoapi_guard/adapters.py (request/response protocol implementations) tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant