HttpResponseStream doesn't work when `end`ing the stream without a `write`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 38/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- aws, node.js, typescript
Línea de trabajo
Empieza leyendo src/HttpResponseStream.js, especialmente el manejo de onBeforeFirstWrite, y luego sigue la ruta de finalización de Node ClientRequest descrita en el issue. Reproduce tanto el caso responseStream.end("Not Found") como el caso responseStream.end() y verifica que el código de estado personalizado y las cabeceras se apliquen en ambos casos.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
When using HttpResponseStream to set the status code and headers on a streaming response, I noticed that if I never call write on the stream, the custom status code and headers don't work.
Example repro:
export const handler = awslambda.streamifyResponse(
async (event, responseStream, context) => {
const metadata = {
statusCode: 404,
headers: { "Content-Type": "text/plain", "X-Foo": "Bar" }
};
responseStream = awslambda.HttpResponseStream.from(responseStream, metadata);
// This will cause a 502 with no custom response headers:
responseStream.end("Not Found");
// This will cause a 200 with no custom response headers:
responseStream.end();
}
);
I believe this is because HttpResponseStream relies on the onBeforeFirstWrite callback:
onBeforeFirstWrite is implemented by overriding http.ClientRequest stream's write:
// https://github.com/aws/aws-lambda-base-images/tree/nodejs18.x -> /var/runtime/index.mjs
req.write = function(chunk, encoding, callback) {
vvverbose("ResponseStream::write", chunk.length, "callback:", typeof callback);
if (typeof chunk !== "string" && !Buffer.isBuffer(chunk) && chunk?.constructor !== Uint8Array) {
chunk = JSON.stringify(chunk);
}
if (status === STATUS_READY && typeof this._onBeforeFirstWrite === "function") {
this._onBeforeFirstWrite((ch) => origWrite(ch));
}
const ret = origWrite(chunk, encoding, callback);
// [snip]
But turns out Node's ClientRequest doesn't call write when ending the stream with a final chunk of data, it calls an internal write_ instead:
I guess this could also be considered a Node bug, because their documentation for ClientRequest.end says:
If
datais specified, it is equivalent to callingrequest.write(data, encoding)followed byrequest.end(callback).
But even if it did implement that contract correctly, there's still the case of ending the stream with no data, i.e., responseStream.end().
- Lenguaje dominante
- TypeScript
- Estrellas
- 224
- Forks
- 60
- Merge medio
- 26 min
- PR fusionados (30 d)
- 2
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de aws/aws-lambda-nodejs-runtime-interface-client
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
aws/aws-lambda-nodejs-runtime-interface-client#198 · 3 comentarios · 6 reacciones ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
aws/aws-lambda-nodejs-runtime-interface-client#195 · 12 reacciones ·
-
bug
aws/aws-lambda-nodejs-runtime-interface-client#170 · 15 comentarios · 6 reacciones · 1 asignado ·
-
AWS Inspector findings for curl Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 38/100
aws/aws-lambda-nodejs-runtime-interface-client#159 · 2 reacciones ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
aws/aws-lambda-nodejs-runtime-interface-client#145 · 1 comentario · 6 reacciones ·
Todos los issues de aws/aws-lambda-nodejs-runtime-interface-client
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
[Bug]: Matrix progress drafts fail with "Matrix runtime not initialized" during tool activity Abiertobug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Client support matrix inclusion Abiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
calcite-components needs triage refactor
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Esri/calcite-design-system#15203 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
danielmiessler/LifeOS#2218 ·