Skip to content

feat(scrape-api): honor inbound X-Request-Id on POST /scrape - #41

Merged
gildesmarais merged 1 commit into
mainfrom
feat/honor-x-request-id
Aug 22, 2026
Merged

feat(scrape-api): honor inbound X-Request-Id on POST /scrape#41
gildesmarais merged 1 commit into
mainfrom
feat/honor-x-request-id

Conversation

@gildesmarais

Copy link
Copy Markdown
Member

Summary

Honor an inbound X-Request-Id on POST /scrape so clients can correlate transport headers with diagnostics.request_id in JSON responses.

What

  • Add resolve_request_id pure function for validating and selecting the effective request id
  • Thread the resolved id through success (200) and error paths (400, 422, 504, collision handling)
  • Accept the header via FastAPI Header on the scrape endpoint
  • Regenerate OpenAPI spec and document behavior in the README

Why

html2rss gem clients can align diagnostics.request_id with the outbound/inbound transport X-Request-Id for end-to-end diagnostics.

Risk

Backward compatible when the header is absent or invalid (server generates/falls back as before).

Test plan

  • make check (ruff, format, hadolint, spectral, unittest — 80 tests OK)

def test_honored_request_id_on_200(self):
from fastapi.testclient import TestClient

import app.main as main_mod
def test_request_id_collision_returns_502(self):
from fastapi.testclient import TestClient

import app.main as main_mod
@gildesmarais
gildesmarais enabled auto-merge (squash) August 22, 2026 14:38
@gildesmarais
gildesmarais merged commit 7fb8643 into main Aug 22, 2026
17 checks passed
@gildesmarais
gildesmarais deleted the feat/honor-x-request-id branch August 22, 2026 14:38
gildesmarais added a commit to html2rss/html2rss that referenced this pull request Aug 22, 2026
## What changed

- `lib/html2rss/request_service/botasaurus_strategy.rb` — each
Botasaurus transport `POST /scrape` sends `User-Agent:
html2rss/<VERSION>`, `Accept: application/json`, `Accept-Encoding:
identity`, and a fresh `X-Request-Id` (UUID) per execute; headers are
covered in `botasaurus_strategy_spec.rb`.
- `spec/fixtures/botasaurus/openapi.yaml` — fixture synced so the scrape
API documents inbound `X-Request-Id`.
- `CONTEXT.md` — notes the gem identifies itself on the Botasaurus hop
and correlates requests via `X-Request-Id`.
- YARD comments on the new transport header constants (lint-yard gate).

## Why

Botasaurus scrape-api logs and support need to distinguish html2rss gem
traffic from other clients and tie a gem execute to a single API
request. Explicit JSON accept/encoding avoids ambiguous Faraday decoding
on the hop.

## Risk

- Low for non-Botasaurus strategies — change is isolated to
`BotasaurusStrategy`.
- End-to-end request correlation depends on botasaurus-scrape-api
honoring inbound `X-Request-Id` (see sibling PR
html2rss/botasaurus-scrape-api#41). Until that merges, the header is
sent but may not appear in API diagnostics.

## Review map

Review map: whole PR is small — start at
`lib/html2rss/request_service/botasaurus_strategy.rb`, then
`spec/lib/html2rss/request_service/botasaurus_strategy_spec.rb`.

## Validation

- Rebased onto `origin/master` (includes compose Sentry DSN merge).
- `make ready` — exit 0
  - RuboCop: 318 files, no offenses
  - yard-lint: no offenses; YARD doc 100% documented
  - `make schema` — generated schema clean (`git diff --exit-code`)
  - Fixture validation — `exe/html2rss validate` on spec fixtures
  - shellcheck — bin scripts clean
- RSpec: 1633 examples, 0 failures; line coverage 98.51%, branch 83.74%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant