Steal code from https://github.com/fengmk2/response-patch