diff --git a/src/ruby/nxt_ruby.c b/src/ruby/nxt_ruby.c index bcb48f6bd..1ab6c07cb 100644 --- a/src/ruby/nxt_ruby.c +++ b/src/ruby/nxt_ruby.c @@ -874,6 +874,18 @@ nxt_ruby_rack_result_headers(nxt_unit_request_info_t *req, VALUE result, } +#define NXT_RUBY_SET_HDR_VALUE(r_value, value, value_end) \ + do { \ + if (TYPE(r_value) == T_STRING) { \ + value = RSTRING_PTR(r_value); \ + value_end = value + RSTRING_LEN(r_value); \ + } else { \ + value = ""; \ + value_end = value; \ + } \ + } while (0); + + static int nxt_ruby_hash_info(VALUE r_key, VALUE r_value, VALUE arg) { @@ -889,16 +901,14 @@ nxt_ruby_hash_info(VALUE r_key, VALUE r_value, VALUE arg) goto fail; } - if (nxt_slow_path(TYPE(r_value) != T_STRING)) { + if (nxt_slow_path(TYPE(r_value) != T_STRING && TYPE(r_value) != T_NIL)) { nxt_unit_req_error(headers_info->req, "Ruby: Wrong header entry 'value' from application"); goto fail; } - value = RSTRING_PTR(r_value); - value_end = value + RSTRING_LEN(r_value); - + NXT_RUBY_SET_HDR_VALUE(r_value, value, value_end); pos = value; for ( ;; ) { @@ -941,11 +951,9 @@ nxt_ruby_hash_add(VALUE r_key, VALUE r_value, VALUE arg) headers_info = (void *) (uintptr_t) arg; rc = &headers_info->rc; - value = RSTRING_PTR(r_value); - value_end = value + RSTRING_LEN(r_value); - key_len = RSTRING_LEN(r_key); + NXT_RUBY_SET_HDR_VALUE(r_value, value, value_end); pos = value; for ( ;; ) {