Skip to content

Instantly share code, notes, and snippets.

@davidjb
Last active October 14, 2015 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidjb/4a89dfb3b9df75da1e67 to your computer and use it in GitHub Desktop.
Save davidjb/4a89dfb3b9df75da1e67 to your computer and use it in GitHub Desktop.
Random hacky snippets for use within Nginx, mostly for debugging purposes.
/* Injecting a header within Nginx core code
* ngx_http_request_t *r; is predefined.
*/
ngx_table_elt_t *h;
h = ngx_list_push(&r->headers_out.headers);
if (h == NULL) {
return NGX_ERROR;
}
h->hash = 1;
ngx_str_set(&h->key, "Header")
ngx_str_set(&h->value, "Value")
/* Logging within the debug log
* debug1 can be debug0 through debug8, depending on the number of arguments to pass
* sprintf formatting can feature %V, for value, %i for integer, etc.
* This example logging outputs the fake header as we defined above.
*/
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "**** %V: %V", &h->key, &h->value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment