diff --git a/src/ngx_http_rds_csv_filter_module.c b/src/ngx_http_rds_csv_filter_module.c index 4fd405b..5f01bf3 100644 --- a/src/ngx_http_rds_csv_filter_module.c +++ b/src/ngx_http_rds_csv_filter_module.c @@ -96,6 +96,15 @@ static ngx_command_t ngx_http_rds_csv_commands[] = { offsetof(ngx_http_rds_csv_loc_conf_t, buf_size), NULL }, + { ngx_string("rds_csv_quote_string"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF + |NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF + |NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_rds_csv_loc_conf_t, quote_string), + NULL }, + ngx_null_command }; @@ -396,6 +405,7 @@ ngx_http_rds_csv_create_loc_conf(ngx_conf_t *cf) conf->field_sep = NGX_CONF_UNSET_UINT; conf->buf_size = NGX_CONF_UNSET_SIZE; conf->field_name_header = NGX_CONF_UNSET; + conf->quote_string = NGX_CONF_UNSET; return conf; } @@ -410,6 +420,8 @@ ngx_http_rds_csv_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) ngx_conf_merge_value(conf->enabled, prev->enabled, 0); ngx_conf_merge_value(conf->field_name_header, prev->field_name_header, 1); + + ngx_conf_merge_value(conf->quote_string, prev->quote_string, 1); ngx_conf_merge_uint_value(conf->field_sep, prev->field_sep, (ngx_uint_t) ','); diff --git a/src/ngx_http_rds_csv_filter_module.h b/src/ngx_http_rds_csv_filter_module.h index ab43c4a..8b589be 100644 --- a/src/ngx_http_rds_csv_filter_module.h +++ b/src/ngx_http_rds_csv_filter_module.h @@ -33,6 +33,7 @@ typedef struct { size_t buf_size; ngx_flag_t field_name_header; ngx_str_t content_type; + ngx_flag_t quote_string; } ngx_http_rds_csv_loc_conf_t; diff --git a/src/ngx_http_rds_csv_output.c b/src/ngx_http_rds_csv_output.c index ca7609a..9c62e88 100644 --- a/src/ngx_http_rds_csv_output.c +++ b/src/ngx_http_rds_csv_output.c @@ -355,7 +355,11 @@ ngx_http_rds_csv_output_field(ngx_http_request_t *r, default: dd("string field found"); - + if (!conf->quote_string) { + dd("no need to quote string."); + size += len; + break; + } val_escape = ngx_http_rds_csv_escape_csv_str(sep, NULL, data, len, &need_quotes); @@ -410,6 +414,11 @@ ngx_http_rds_csv_output_field(ngx_http_request_t *r, default: /* string */ + if (!conf->quote_string) { + dd("no need to quote string, just copy string buffer."); + last = ngx_copy(last, data, len); + break; + } if (need_quotes) { *last++ = '"'; } @@ -492,7 +501,11 @@ ngx_http_rds_csv_output_more_field_data(ngx_http_request_t *r, default: /* string */ - + if (!conf->quote_string) { + dd("no need to quote string."); + size += len; + break; + } escape = ngx_http_rds_csv_escape_csv_str(sep, NULL, data, len, &need_quotes); @@ -530,6 +543,11 @@ ngx_http_rds_csv_output_more_field_data(ngx_http_request_t *r, default: /* string */ + if (!conf->quote_string) { + dd("no need to quote string, just copy string buffer."); + last = ngx_copy(last, data, len); + break; + } if (escape == 0) { last = ngx_copy(last, data, len);