Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am davidcaste on github.
* I am dcastellanos (https://keybase.io/dcastellanos) on keybase.
* I have a public key ASDnqQ7mE6pLebdm74Z4fmlg36Ki14YQQSkuwQkWsh6RCwo
To claim this, I am signing this object:
@davidcaste
davidcaste / gist:ea10f1c48a2d0007b51e
Created May 12, 2015 16:26
Another attempt to inflate a gzip file in Lua with output size restrictions
-- Debian package nginx-extras and lzlib (https://github.com/LuaDist/lzlib) required
MAX_BUFFER_SIZE = 1048576
function inflate_body (data)
local inflate = require("zlib").inflate(data)
local buffer = ""
repeat
@davidcaste
davidcaste / inflate_body.lua
Last active January 9, 2024 10:17
Nginx config: receive a request with a gzipped body, inflate it, and pass it to a proxied server
-- Debian packages nginx-extras, lua-zlib required
ngx.ctx.max_chunk_size = tonumber(ngx.var.max_chunk_size)
ngx.ctx.max_body_size = tonumber(ngx.var.max_body_size)
function create_error_response (code, description)
local message = string.format('{"status":400,"statusReason":"Bad Request","code":%d,"exception":"","description":"%s","message":"HTTP 400 Bad Request"}', code, description)
ngx.status = ngx.HTTP_BAD_REQUEST
ngx.header.content_type = "application/json"
ngx.say(message)
@davidcaste
davidcaste / gist:3294320
Created August 8, 2012 11:13
Yet another regex to check URLs
# Capture entire matched URL
(
# Optional: only allow some network protocols
# URL protocol and a colon followed by 2 slashes
(?:
(?:
http|https|ftp
):\\/\\/
)?