From f81aa02448b615c4d5fc4f6544c53289dae9d2ec Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 4 May 2011 16:41:36 -0700 Subject: return 414 for URI length violations There's an HTTP status code allocated for it in , so return that instead of 400. --- ext/unicorn_http/global_variables.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ext/unicorn_http/global_variables.h') diff --git a/ext/unicorn_http/global_variables.h b/ext/unicorn_http/global_variables.h index cdbc42d..cda7f24 100644 --- a/ext/unicorn_http/global_variables.h +++ b/ext/unicorn_http/global_variables.h @@ -1,6 +1,7 @@ #ifndef global_variables_h #define global_variables_h static VALUE eHttpParserError; +static VALUE eRequestURITooLongError; static VALUE g_rack_url_scheme; static VALUE g_request_method; @@ -36,6 +37,7 @@ static VALUE g_http_11; "HTTP element " # N " is longer than the " # length " allowed length." NORETURN(static void parser_error(const char *)); +NORETURN(static void raise_414(const char *)); /** * Validates the max length of given input and throws an HttpParserError @@ -46,6 +48,11 @@ NORETURN(static void parser_error(const char *)); parser_error(MAX_##N##_LENGTH_ERR); \ } while (0) +#define VALIDATE_MAX_URI_LENGTH(len, N) do { \ + if (len > MAX_##N##_LENGTH) \ + raise_414(MAX_##N##_LENGTH_ERR); \ +} while (0) + /** Defines global strings in the init method. */ #define DEF_GLOBAL(N, val) do { \ g_##N = rb_obj_freeze(rb_str_new(val, sizeof(val) - 1)); \ -- cgit v1.2.3-24-ge0c7