Skip to content

Instantly share code, notes, and snippets.

@rezan
Created September 26, 2018 13:43
Show Gist options
  • Select an option

  • Save rezan/df245bc83854893d00948757a7915cfe to your computer and use it in GitHub Desktop.

Select an option

Save rezan/df245bc83854893d00948757a7915cfe to your computer and use it in GitHub Desktop.
Test JSON response body parsing with nesting
varnishtest "Test JSON response body parsing with nesting"
server s1 {
rxreq
txresp -body {
{
"key":"value",
"key2":23,
"2": {
"nested":"goal"
}
}
}
} -start
varnish v1 -vcl+backend {
import edgestash;
import json;
import std;
sub vcl_backend_response {
edgestash.index_json();
}
sub vcl_deliver {
if (edgestash.is_json()) {
json.parse_resp_index();
set resp.http.X-json = json.length();
set resp.http.X-key = json.get("key", "");
set resp.http.X-key2 = json.get("key2", "");
set resp.http.X-2-nested = json.get("2.nested", "");
std.log("JSON: " + json.get(".", ""));
json.parse(json.get("2", ""));
std.log("JSON nested: " + json.get(".", ""));
}
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.X-json == "3"
expect resp.http.X-key == "value"
expect resp.http.X-key2 == "23"
expect resp.http.X-2-nested == "goal"
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment