[Server] Decode an HTTP request body once instead of per pipeline stage

Abierto
#733 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
php

Línea de trabajo

Start with InboundClassifier::classify(), Protocol and StatelessProtocol, MessageFactory::create(), and Json::objectsToArrays() to trace how the request body is decoded across the StreamableHttpTransport pipeline. Check the HTTP transport tests and add coverage showing that one decoded message is shared through classification and handling. Update docs/run/http.md to explain that maxBodyBytes limits encoded bytes and that decoded memory use depends on body shape; the issue leaves whether to lower the default unresolved.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

enhancement P3

Currently a POST body is decoded several times before it reaches a handler: InboundClassifier::classify(), then Protocol or StatelessProtocol, then MessageFactory::create() and Json::objectsToArrays(). Not all copies are alive at the same time, but peak memory ends up at about twice a single decode, and the CPU cost is paid on every pass - also for requests that are rejected right after.

Measured on main with a tools/call for an unknown tool through StreamableHttpTransport:

body (600 KB) one json_decode() full pipeline
list of [0] 35.6 MB 74.4 MB
list of {"a":0} 31.9 MB 68.4 MB
list of {} 4.0 MB 33.4 MB
list of ints 8.0 MB 19.1 MB

Two things to do:

  • decode once at the edge and pass the decoded message down, so classification, the protocol and the MessageFactory share it
  • document in docs/run/http.md that maxBodyBytes bounds bytes, not decoded size - adversarial shapes need ~60x the body in memory, so the cap should be sized against memory_limit. Maybe also worth lowering the 4 MiB default.

Reported by @kanokwut.

Lenguaje dominante
PHP
Estrellas
1.7k
Forks
206
Merge medio
1 d 17 h
PR fusionados (30 d)
102

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de modelcontextprotocol/php-sdk

Todos los issues de modelcontextprotocol/php-sdk

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.