datasette --get --headers option, closes #2578

This commit is contained in:
Simon Willison 2025-11-04 18:12:15 -08:00
commit ce464da34b
3 changed files with 23 additions and 1 deletions

View file

@ -445,7 +445,7 @@ def uninstall(packages, yes):
@click.option( @click.option(
"--headers", "--headers",
is_flag=True, is_flag=True,
help="Include HTTP headers in --get output (requires --get)", help="Include HTTP headers in --get output",
) )
@click.option( @click.option(
"--token", "--token",

View file

@ -121,6 +121,7 @@ Once started you can access it at ``http://localhost:8001``
the root user the root user
--get TEXT Run an HTTP GET request against this path, --get TEXT Run an HTTP GET request against this path,
print results and exit print results and exit
--headers Include HTTP headers in --get output
--token TEXT API token to send with --get requests --token TEXT API token to send with --get requests
--actor TEXT Actor to use for --get requests (JSON string) --actor TEXT Actor to use for --get requests (JSON string)
--version-note TEXT Additional note to show on /-/versions --version-note TEXT Additional note to show on /-/versions

View file

@ -52,6 +52,27 @@ def test_serve_with_get(tmp_path_factory):
pm.unregister(to_unregister) pm.unregister(to_unregister)
def test_serve_with_get_headers():
runner = CliRunner()
result = runner.invoke(
cli,
[
"serve",
"--memory",
"--get",
"/_memory/",
"--headers",
],
)
# exit_code is 1 because it wasn't a 200 response
assert result.exit_code == 1, result.output
assert result.output == (
"HTTP/1.1 302\n"
"location: /_memory\n"
"content-type: text/html; charset=utf-8\n"
)
def test_serve_with_get_and_token(): def test_serve_with_get_and_token():
runner = CliRunner() runner = CliRunner()
result1 = runner.invoke( result1 = runner.invoke(