The cookbook example "Accessing HTTP Response Metadata While Streaming" doesn't stream
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 58/100
- Tipo de issue
- Documentación
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- shell
- Área
- documentation
Línea de trabajo
Comienza con el ejemplo del cookbook titulado "Accessing HTTP Response Metadata While Streaming" y reprodúcelo contra https://example.com. Determina una forma de streaming más limpia que las soluciones alternativas mostradas con $in o una expresión condicional; se considera terminado cuando se imprimen el estado y el tipo de contenido mientras el cuerpo HTTP sigue disponible para el comando lines siguiente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
The example in question is:
http get --allow-errors https://api.example.com/events.jsonl
| metadata access {|meta|
print $"Status: ($meta.http_response.status)"
print $"Content-Type: ($meta.http_response.headers | where name == content-type | get value.0)"
if $meta.http_response.status != 200 {
error make {msg: $"Failed with status ($meta.http_response.status)"}
} else { }
}
| lines
| each { from json }
| where event_type == "error"
This won't work because the input to the closure is fed to the first statement, which is print $"Status: ...", while the closure output is taken from else {}. If the http response status is 200, the closure will always output nothing because the input for the closure was consumed by print. We can't test this because api.example.com is a fake subdomain, so let's modify the example to use example.com and not assume the output is json:
http get --allow-errors https://example.com
| metadata access {|meta|
print $"Status: ($meta.http_response.status)"
print $"Content-Type: ($meta.http_response.headers | where name == content-type | get value.0)"
if $meta.http_response.status != 200 {
error make {msg: $"Failed with status ($meta.http_response.status)"}
} else { }
}
| lines
If you run this, you will see that the status and content type are printed, but the http body is not returned from the closure.
One solution is to use the $in variable to collect the input and return it from the else statement:
http get --allow-errors https://example.com
| metadata access {|meta|
let input = $in
print $"Status: ($meta.http_response.status)"
print $"Content-Type: ($meta.http_response.headers | where name == content-type | get value.0)"
if $meta.http_response.status != 200 {
error make {msg: $"Failed with status ($meta.http_response.status)"}
} else { $input }
}
| lines
This does return the http body from the closure, but the example is called "Accessing HTTP Response Metadata While Streaming", and $in collects the input, so it's no longer a stream.
If we want to make this work while streaming, we can make the if statement into the only top level statement of the closure by moving the print statements into its conditional expression:
http get --allow-errors https://example.com
| metadata access {|meta|
if (
print $"Status: ($meta.http_response.status)";
print $"Content-Type: ($meta.http_response.headers | where name == content-type | get value.0)";
$meta.http_response.status != 200
) {
error make {msg: $"Failed with status ($meta.http_response.status)"}
} else { }
}
| lines
When run, this streams the http body after printing the status and content-type. However, it is pretty hacky. If we were to put this in the cookbook, it would need an accompanying explanation as to how sticking statements in the conditional expression prevents them from eating the closure input. Perhaps someone with more nushell experience than me can come up with a cleaner way to write this?
- Lenguaje dominante
- TypeScript
- Estrellas
- 260
- Forks
- 563
- Merge medio
- 5 h 9 min
- PR fusionados (30 d)
- 16
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la 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 nushell/nushell.github.io
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 68/100
nushell/nushell.github.io#2081 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
nushell/nushell.github.io#767 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 58/100
nushell/nushell.github.io#2209 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
nushell/nushell.github.io#2194 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 48/100
nushell/nushell.github.io#2155 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de nushell/nushell.github.io
Issues similares
-
bug HemiStake
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
hemilabs/ui-monorepo#2413 ·
Los mantenedores suelen responder en 1 día
-
component/ui framework/react kind/bug language/javascript
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
meshery/meshery#22216 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
company delete fails with 500 on any company that has activity (cost events, inbox dismissals)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
paperclipai/paperclip#14982 ·
Los mantenedores suelen responder en 1 día
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
lingdojo/kana-dojo#31515 · 1 comentario · 5 reacciones ·
Los mantenedores suelen responder en 1 día