Last active
January 17, 2019 15:16
-
-
Save rezan/244bdd61dcfd08ce6e1ae90c95e5e71b to your computer and use it in GitHub Desktop.
Varnish GRPC VCL
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
# GRPC VCL | |
vcl 4.0; | |
import bodyaccess; | |
import http; | |
import std; | |
import synthbackend; | |
backend default { | |
.host = "0"; | |
.port = "0"; | |
} | |
sub vcl_recv { | |
set req.http.X-method = req.method; | |
std.cache_req_body(1MB); | |
if (req.method == "HEAD" || req.method == "GET" || req.method == "POST") { | |
return (hash); | |
} | |
return (pass); | |
} | |
sub vcl_hash { | |
hash_data(req.http.X-method); | |
bodyaccess.hash_req_body(); | |
} | |
sub vcl_backend_fetch { | |
set bereq.method = bereq.http.X-method; | |
http.init(0); | |
http.req_set_method(0, bereq.method); | |
http.req_set_url(0, "http://grpc_host:50051" + bereq.url); | |
http.req_set_iparam(0, "HTTP_VERSION", 5); | |
http.req_set_header(0, "te", "trailers"); | |
http.req_copy_headers(0); | |
http.req_copy_body(0); | |
http.req_send(0); | |
http.resp_wait(0); | |
if (http.resp_get_errorcode(0) != 0) { | |
return (abandon); | |
} | |
set bereq.backend = synthbackend.from_blob(http.resp_get_body_blob(0)); | |
} | |
sub vcl_backend_response { | |
set beresp.status = http.resp_get_status(0); | |
http.resp_copy_headers(0); | |
if (!beresp.http.grpc-status) { | |
set beresp.http.grpc-status = "0"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment