Welcome! Log In Create A New Profile

Advanced

[nginx module] Save response into temp file

Hung Nguyen
September 23, 2014 04:12AM
Hi,
I am working on an nginx module, that has flow:

receive user request -> parse request -> read local file -> process file -> response to client

This flow is working well. But now we have another requirement. Afer process this file and build response into ngx_chain, I want to write response content into ngx_temp_file to do another job, after that return response to client

receive user request -> parse request -> read local file -> process file -> save the processed file to temp file -> response to client


I use this code to write file:=20


ngx_temp_file_t *tf;
tf =ngx_pcalloc(r->pool, sizeof (ngx_temp_file_t));
tf->file.fd = NGX_INVALID_FILE;
tf->file.log = nlog;
tf->path = clcf->client_body_temp_path;
tf->pool = r->pool;
tf->persistent = 1;
rc = ngx_create_temp_file(&tf->file, tf->path, tf->pool, tf->=
persistent, tf->clean, tf->access);
ngx_write_chain_to_file(&tf->file, m->chain, m->content_length,=
r->pool);


File can be written into temporary file with following name:

-rw------- 1 root root 455712 Sep 23 13:58 0000000001
-rw------- 1 root root 455712 Sep 23 13:58 0000000002
-rw------- 1 root root 2748936 Sep 23 13:58 0000000003
-rw------- 1 root root 2831656 Sep 23 13:58 0000000004
-rw------- 1 root root 2826016 Sep 23 13:58 0000000005
-rw------- 1 root root 1786000 Sep 23 13:58 0000000006

But I cannot read from it. It seems like content of these file is not just =
(or not enough) content that user browser receive.
Let say If nginx receive user request: http://server.com/document.txt?type=csv , our module will process the original document.txt file, process file to make it csv type, save it to ngx_temp_file, and return to client document.csv file. But the file that was saved into ngx_temp_file is not csv file.
Please show me what I am doing wrong on this.

Thanks,

-
Hung
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

[nginx module] Save response into temp file

Hung Nguyen September 23, 2014 04:12AM

Re: [nginx module] Save response into temp file

hungnguyen September 24, 2014 05:03AM

Re: [nginx module] Save response into temp file

wandenberg September 24, 2014 08:36AM

Re: [nginx module] Save response into temp file

hungnguyen October 09, 2014 07:10AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 228
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready