Hi there,

I wonder if this can be done with uwsgi:

I want to use uwsgi to do custom HTTP routing, generally a mixture to what is 
described here

        http://uwsgi-docs.readthedocs.org/en/latest/Fastrouter.html (in section 
"Way 5 - fastrouter-use-code-string")

and 

        http://projects.unbit.it/uwsgi/wiki/CustomRouting (old documentation)

I need to route HTTP requests, based on information in the HTTP request body.

What I have:

        - a uwsgi server started in emperor mode serving 2 custom apps (app_a 
on socket 3065, app_b on socket 3066) and a custom router (on socket 3031).

        - both app_a and app_b are python wsgi apps in my current setup, e.g.

                        # app a
                        def application(env, start_response):
                            start_response('200 OK', 
[('Content-Type','text/html')])
                            return "<html><body>Hello World 
<b>A</b>!</body></html>"

          but should be anything that uwsgi does support as a uwsgi app.

        - all HTTP requests (e.g. from nginx) go to the custom router.

        - the custom router reads the body, decides if app_a or app_b is 
responsible for handling the HTTP request and forwards the request to the 
corresponding socket, like this (pseudo code):

                        import uwsgi 

                        def handle(env):
                                # I need to read the whole body here, e.g. 
env['wsgi.input'].read()
                                # but how to "rewind" the read so that 
subsequent uwsgi.send_message work as expected?
                                # decide on the port based on the body 
                                port = ...
                                return port

                        def application(env, start_response):
                                port = handle(env)
                                fd = ':30' + str(port)
                                # how to forward the unaltered body to the 
other uwsgi workers (app_a/app_b)?
                                for part in uwsgi.send_message(fd, 0, 0, env, 
0, env['wsgi.input'].fileno(), env['uwsgi.cl']:
                                        yield part

My problem is with reading and rewinding the body for the upcoming 
uwsgi.send_message call. I tried various means to read the body to a temporary 
file, and use that for the .send_message call but I had no success so far.

I tried to solve this problem with an older version uwsgi (1.2 I believe) but 
to no avail. I'm happy to upgrade to 1.4 or even more recent work-in-progress 
versions as long as I can create a working prototype with uwsgi. 

Is this possible with uwsgi?

Any help is appreciated.

Kind regards,
K.

On 26.02.2013, at 13:13, Marcin Deranek <[email protected]> wrote:

> On Tue, 26 Feb 2013 12:57:06 +0100
> "Roberto De Ioris" <[email protected]> wrote:
> 
>> I have tried reproducing it for hours but without luck :(
>> 
>> The only thing i can think of, is some difference in the keyname you
>> are using (i mean, i write something but you ask for another).
>> 
>> Are you using python3 ?
> 
> No, uwsgi 1.4.6 + perl 5.14.2 on CentOS 5.4 (glibc-2.5-42)
> 
>> May i ask you to try with uWSGI 1.9 (+ stats enabled) as it exports
>> internal cache statistics ?
> 
> Will give it a shot..
> 
> Marcin
> _______________________________________________
> uWSGI mailing list
> [email protected]
> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to