Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `column` charts now display vertical bars instead of nothing at all.
- `stacked` is now ignored on chart types that cannot stack, instead of displaying an empty chart.
- Screen readers now announce the title of the modal component instead of an unnamed dialog.
- `sqlpage.fetch_with_meta` now returns JSON response bodies under the documented `body` key.

## v0.45

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(super) async fn fetch_with_meta(
decode_response(body_bytes, http_request.response_encoding.as_deref())?;
if is_json {
obj.serialize_entry(
"json_body",
"body",
&serde_json::value::RawValue::from_string(body_str)?,
)?;
} else {
Expand Down
21 changes: 15 additions & 6 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,21 @@ pub fn start_echo_server(shutdown: oneshot::Receiver<()>) -> (JoinHandle<()>, u1
let listener = std::net::TcpListener::bind("localhost:0").unwrap();
let port = listener.local_addr().unwrap().port();
let server = HttpServer::new(|| {
App::new().default_service(fn_service(|mut req: ServiceRequest| async move {
let meta = format_request_line_and_headers(&req);
let body = format_body(&mut req).await;
let resp = build_echo_response(body, meta);
Ok(req.into_response(resp))
}))
App::new()
.route(
"/json",
web::to(|body: web::Bytes| async move {
HttpResponse::Ok()
.insert_header((header::CONTENT_TYPE, "application/json"))
.body(body)
}),
)
.default_service(fn_service(|mut req: ServiceRequest| async move {
let meta = format_request_line_and_headers(&req);
let body = format_body(&mut req).await;
let resp = build_echo_response(body, meta);
Ok(req.into_response(resp))
}))
})
.workers(1)
.listen(listener)
Expand Down
5 changes: 5 additions & 0 deletions tests/sql_test_files/data/fetch_with_meta_json_body.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set url = 'http://localhost:' || $echo_port || '/json';
set fetch_req = '{"method":"POST","url":"' || $url || '","body":{"hello":"world"}}';
set res = sqlpage.fetch_with_meta($fetch_req);

select '"body":{"hello":"world"}' as expected_contains, $res as actual;