Skip to content

Instantly share code, notes, and snippets.

Thijs Feryn ThijsFeryn

Block or report user

Report or block ThijsFeryn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ThijsFeryn
ThijsFeryn / Dockerfile
Last active Jul 4, 2017
Dockerized Hello NodeJS example to test Kubernetes
View Dockerfile
FROM node:6.9.2
EXPOSE 8080
COPY server.js .
CMD node server.js
@ThijsFeryn
ThijsFeryn / call_jwt.vcl
Last active Feb 13, 2017
Call the custom-defined JWT VCL procedure that checks the validity of a JSON Web Token. This VCL snippet requires vmod_digest and https://gist.github.com/ThijsFeryn/b745c42dbfa328d702b8dbba8777aee2
View call_jwt.vcl
vcl 4.0;
import digest;
backend default {
.host = "localhost";
.port = "8080";
}
include "jwt.vcl";
@ThijsFeryn
ThijsFeryn / jwt.vcl
Created Feb 13, 2017
A custom VCL procedure that validates a JSON Web Token. This procedure can be called from within your other VCL logic. You will need to install vmod_digest to have the digest functions.
View jwt.vcl
sub jwt {
if(req.http.cookie ~ "^([^;]+;[ ]*)*token=[^\.]+\.[^\.]+\.[^\.]+([ ]*;[^;]+)*$") {
set req.http.x-token = ";" + req.http.Cookie;
set req.http.x-token = regsuball(req.http.x-token, "; +", ";");
set req.http.x-token = regsuball(req.http.x-token, ";(token)=","; \1=");
set req.http.x-token = regsuball(req.http.x-token, ";[^ ][^;]*", "");
set req.http.x-token = regsuball(req.http.x-token, "^[; ]+|[; ]+$", "");
set req.http.tmpHeader = regsub(req.http.x-token,"token=([^\.]+)\.[^\.]+\.[^\.]+","\1");
set req.http.tmpTyp = regsub(digest.base64url_decode(req.http.tmpHeader),{"^.*?"typ"\s*:\s*"(\w+)".*?$"},"\1");
@ThijsFeryn
ThijsFeryn / jwt.vcl
Created Feb 13, 2017
A custom VCL procedure that validates a JSON Web Token. This procedure can be called from within your other VCL logic. Wath
View jwt.vcl
sub jwt {
if(req.http.cookie ~ "^([^;]+;[ ]*)*token=[^\.]+\.[^\.]+\.[^\.]+([ ]*;[^;]+)*$") {
set req.http.x-token = ";" + req.http.Cookie;
set req.http.x-token = regsuball(req.http.x-token, "; +", ";");
set req.http.x-token = regsuball(req.http.x-token, ";(token)=","; \1=");
set req.http.x-token = regsuball(req.http.x-token, ";[^ ][^;]*", "");
set req.http.x-token = regsuball(req.http.x-token, "^[; ]+|[; ]+$", "");
set req.http.tmpHeader = regsub(req.http.x-token,"token=([^\.]+)\.[^\.]+\.[^\.]+","\1");
set req.http.tmpTyp = regsub(digest.base64url_decode(req.http.tmpHeader),{"^.*?"typ"\s*:\s*"(\w+)".*?$"},"\1");
@ThijsFeryn
ThijsFeryn / return_vcl.vcl
Created Sep 20, 2016
Returning custom VCLs on-the-fly
View return_vcl.vcl
sub vcl_recv {
if (req.http.host == "blog.feryn.eu") {
return(vcl(blog_vcl));
}
if (req.http.host == "talks.feryn.eu") {
return(vcl(talks_vcl));
}
}
@ThijsFeryn
ThijsFeryn / load_and_label
Created Sep 20, 2016
Load and label VCL files
View load_and_label
vcl.load blog /etc/varnish/blog.vcl
vcl.load talks /etc/varnish/talks.vcl
vcl.label blog_vcl blog
vcl.label talks_vcl talks
@ThijsFeryn
ThijsFeryn / varnish5_proxy_backend.vcl
Created Sep 20, 2016
Varnish 5 offers backend PROXY protocol support. If you add the ".proxy_header" attribute, the PROXY protocol will be used.
View varnish5_proxy_backend.vcl
backend default {
.host = "127.0.0.1";
.port = "8080";
.proxy_header = 1;
}
@ThijsFeryn
ThijsFeryn / output_type_error.php
Created Jul 14, 2016
The returned array cannot be converted into the desired string. A type error is thrown.
View output_type_error.php
<?php
function double(int $argument):string {
return [$argument*2];
}
var_dump(double(3));
@ThijsFeryn
ThijsFeryn / input_type_error.php
Created Jul 14, 2016
A type error is thrown because an array cannot be turned into an integer
View input_type_error.php
<?php
function double(int $argument):int {
return $argument*2;
}
var_dump(double([]));
@ThijsFeryn
ThijsFeryn / output_coerce.php
Created Jul 14, 2016
Coerce returned integer into a string. No type error thrown despite the return type declaration.
View output_coerce.php
<?php
function double(int $argument):string {
return $argument*2;
}
var_dump(double(3));
You can’t perform that action at this time.