Skip to content

Instantly share code, notes, and snippets.

@rezan
Created September 25, 2018 15:23
Show Gist options
  • Select an option

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

Select an option

Save rezan/0c817c4afcb17df0ec284ddd75405950 to your computer and use it in GitHub Desktop.
Test JSON response body parsing
varnishtest "Test JSON response body parsing"
server s1 {
rxreq
txresp -body {
{
"key":"value",
"key2":23
}
}
} -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", "");
std.log("JSON: " + json.get(".", ""));
}
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.X-json == "2"
expect resp.http.X-key == "value"
expect resp.http.X-key2 == "23"
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment