Skip to content

add command "rds_csv_quote_string"=on/off #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ngx_http_rds_csv_filter_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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;
}
Expand All @@ -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) ',');
Expand Down
1 change: 1 addition & 0 deletions src/ngx_http_rds_csv_filter_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
22 changes: 20 additions & 2 deletions src/ngx_http_rds_csv_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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++ = '"';
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down