A Flask-based HTTP API that accepts base64-encoded DNS queries (RFC1035), decodes and parses them, logs request/response, and returns DNS questions and answers in JSON. It includes rate-limiting via Redis and DNS resolution fallback to local and public resolvers.
- Accepts base64-encoded DNS queries via
POST /dns/queries
- Parses multiple DNS questions (RFC1035)
- Returns JSON with ID, questions, and DNS answers
- Performs DNS resolution with local and fallback resolvers
- Implements IP-based rate limiting using Redis
- Returns
429 Too Many Requests
withRetry-After
header - Supports caching with
ETag
andIf-None-Match
- Exposes health check at
/healthz
dns_parser/
├── dns_querier/ # Flask app logic
├── client/ # CLI tool to send DNS queries
├── e2e/ # End-to-end tests using testcontainers
├── tests/ # Unit tests
├── Dockerfile.server # Multi-stage minimal server image
├── docker-compose.yml
├── pyproject.toml
├── README.md
This project uses testcontainers
to run integration and e2e tests in isolated Docker-based environments.
poetry install
poetry run pytest
This will automatically spin up a Redis container for rate-limiting tests.
poetry run python run.py
docker build -f Dockerfile.server -t dns-parser-server .
docker run -p 5000:5000 dns-parser-server
Health check:
curl http://localhost:5000/healthz
The project includes a simple CLI tool to send DNS queries:
poetry run python client/cli.py www.google.com
You can change the endpoint URL using:
poetry run python client/cli.py www.google.com --url http://localhost:5000/dns/queries
- All tests are run via CI using
pytest
- Docker image builds are only triggered if tests pass
- Separate workflows are used for test and image build stages
MIT