api: HEAD requests fail for derived JSON endpoints

Aperta Adatta ai principianti
#12,413 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
api, backend

Direzione di ricerca

Inizia da packages/function/src/worker.ts: la funzione catalogResponse (circa righe 209-224) e la route dello schema (circa righe 67-73). Entrambe chiamano .json() su un asset o una risposta API che è vuota per le richieste HEAD. Riproduci con curl -I 'https://models.dev/model-schema.json' e con la query multi-tipo api.json?type=.... È completato quando HEAD restituisce lo stesso stato e gli stessi header di GET senza analizzare un body, i 15 test esistenti del worker continuano a passare e ci sono nuovi test di regressione HEAD per le route dello schema e multi-tipo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

HEAD returns 500 for /model-schema.json and multi-type catalog requests, while the corresponding GET requests return 200. Plain /api.json works with both methods.

Reproduced locally and on the public site; still present on current dev, 8b715df235126f6efcf4ab9b2e41c45f5ec74184.

Reproduction

curl -I 'https://models.dev/api.json'                     # 200, control
curl -I 'https://models.dev/api.json?type=chat,decision'  # 500
curl -I 'https://models.dev/model-schema.json'           # 500
curl -sS -o /dev/null -w '%{http_code}\n' \
  'https://models.dev/model-schema.json'                 # GET: 200

Cause

In catalogResponse, the asset request inherits HEAD. The asset correctly has no response body, but the multi-type path calls assetResponse.json(). The schema route similarly calls apiResponse.json(). Both throw SyntaxError: Unexpected end of JSON input.

Local regression tests reproduce this on all four multi-type catalog routes and on schema requests. GET/static-HEAD controls, invalid-type 400 and conditional HEAD/304 pass. A separate real loopback HTTP asset server reproduces the schema failure too. The failures repeated across ten runs; the existing 15 worker tests pass. Environment: macOS 15.6.1/arm64, Bun 1.4.4.

Expected: return the appropriate metadata without parsing a bodyless asset response or sending HEAD response content. See RFC 9110, 9.3.2.

I'd like to work on a fix limited to HEAD handling and regression tests, keeping GET output, type validation, ETags/304s and CORS unchanged. Would that scope fit?

Lingua principale
TypeScript
Stelle
7.5k
Fork
2k
Merge medio
40m
PR unite (30g)
916

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di anomalyco/models.dev

Tutte le issue di anomalyco/models.dev

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.