# Create a Request from a String

**URL:** <https://www.ruby-forum.com/t/create-a-request-from-a-string/189133>\
**Category:** NGINX\
**Created:** [May 25, 2010, 7:52am UTC](https://www.ruby-forum.com/t/create-a-request-from-a-string/189133 "2010-05-25T07:52:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthieu\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@Matthieu\_T](https://www.ruby-forum.com/u/Matthieu_T)\
**Post date:** [May 25, 2010, 7:52am UTC](https://www.ruby-forum.com/t/create-a-request-from-a-string/189133/1 "2010-05-25T07:52:28Z")

</div>

Hi,

I’m trying to store requests that comes in (let’s call it request A),  
and I  
want to be able to “replay” them later, when another query comes in with  
a  
specific argument (request B).  
I can store the request to memcache, and get it back later. But I can’t  
figure out how to recreate a query from a string.

The only way I can think about would be to use an upstream module with  
the  
create\_request method, but I would like to avoid duplicating most of the  
proxy module,  
and I don’t necessarily want to send the saved query to an upstream.

So while processing request B, I get the saved request A as a string. Is  
there at that point a way to create a request from that string like if  
it  
was going through ngx\_http\_process\_request\_line() ?

Thank you,

Matthieu.

---

<div class="post-metadata">

**Author:** ![Matthieu\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@Matthieu\_T](https://www.ruby-forum.com/u/Matthieu_T)\
**Post date:** [May 25, 2010, 10:20am UTC](https://www.ruby-forum.com/t/create-a-request-from-a-string/189133/2 "2010-05-25T10:20:35Z")

</div>

Hi,

> I’m trying to store requests that comes in (let’s call it request A), and  
> I  
> want to be able to “replay” them later, when another query comes in with a  
> specific argument (request B).  
> I can store the request to memcache, and get it back later. But I can’t  
> figure out how to recreate a query from a string.

You can do this with both: ngx\_echo [1] and ngx\_lua [2].

You should also read agentzh’s post on that matter [3],  
it will answer pretty much all of your questions 😉

[1] [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/NginxHttpEchoModule)  
[2] [GitHub - openresty/lua-nginx-module: Embed the Power of Lua into NGINX HTTP servers · GitHub](http://github.com/chaoslawful/lua-nginx-module)  
[3] [http://agentzh.spaces.live.com/blog/cns!FF3A735632E41548!560.entry](http://agentzh.spaces.live.com/blog/cns!FF3A735632E41548!560.entry)

Best regards,  
Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>

---

<div class="post-metadata">

**Author:** ![Matthieu\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@Matthieu\_T](https://www.ruby-forum.com/u/Matthieu_T)\
**Post date:** [May 25, 2010, 8:16pm UTC](https://www.ruby-forum.com/t/create-a-request-from-a-string/189133/3 "2010-05-25T20:16:34Z")

</div>

On Tue, May 25, 2010 at 1:19 AM, Piotr S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> You can do this with both: ngx\_echo [1] and ngx\_lua [2].
> 
> You should also read agentzh’s post on that matter [3],  
> it will answer pretty much all of your questions 😉
> 
> [1] [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/NginxHttpEchoModule)  
> [2] [GitHub - openresty/lua-nginx-module: Embed the Power of Lua into NGINX HTTP servers · GitHub](http://github.com/chaoslawful/lua-nginx-module)  
> [3] [http://agentzh.spaces.live.com/blog/cns!FF3A735632E41548!560.entry](http://agentzh.spaces.live.com/blog/cns!FF3A735632E41548!560.entry)

Thanks for the pointers, but it doesn’t really answer my question.  
Agentzh’s post shows how to send the content fetched from memcached to  
the  
downstream.

I’m trying to send that content representing a request, to an upstream.  
Basically “replaying” a query stored as a string, exactly as if it was  
coming from an open socket.

Thank you,

Matthieu.

---

<div class="post-metadata">

**Author:** ![Matthieu\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@Matthieu\_T](https://www.ruby-forum.com/u/Matthieu_T)\
**Post date:** [May 26, 2010, 3:40am UTC](https://www.ruby-forum.com/t/create-a-request-from-a-string/189133/4 "2010-05-26T03:40:14Z")

</div>

On Wed, May 26, 2010 at 2:14 AM, Matthieu T.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for the pointers, but it doesn’t really answer my question.  
> Agentzh’s post shows how to send the content fetched from memcached to the  
> downstream.

Aye 🙂

> I’m trying to send that content representing a request, to an upstream.  
> Basically “replaying” a query stored as a string, exactly as if it was  
> coming from an open socket.

Basically it’s boiled down to manipulating r-\>headers\_in and  
r-\>request\_body in a rewrite or access phase handler and then forward  
to request object to the upstream handler (remember upstream is a  
content handler pe se?) 🙂

ngx\_headers\_more has the code for the former while ngx\_chunkin and  
ngx\_echo do have some examples for the latter 🙂

Cheers,  
-agentzh
