Created
September 25, 2018 15:23
-
-
Save rezan/0c817c4afcb17df0ec284ddd75405950 to your computer and use it in GitHub Desktop.
Test JSON response body parsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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