subrequest headers

57 views
Skip to first unread message

Andries

unread,
Apr 7, 2014, 2:07:03 PM4/7/14
to nx...@googlegroups.com
Hi Yaroslav,

Is it possible to create headers for a subrequest (something like nxweb_add_response_header_safe)?

Andries

Yaroslav

unread,
Apr 7, 2014, 2:52:10 PM4/7/14
to nx...@googlegroups.com
Hi Andries,

How do you launch subrequests? What function do you use and what kind of headers you wish to pass?

Subrequests are somewhat limited in terms that they cannot process POST requests, they must not gzip their responses, etc. Therefore not all headers could be safe to pass.

Can't you pass desired parameters via subrequest URI?

Yaroslav



--
You received this message because you are subscribed to the Google Groups "nxweb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nxweb+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andries

unread,
Apr 8, 2014, 5:08:21 AM4/8/14
to nx...@googlegroups.com
I use composite stream with the proxy filter in the subrequest.

OK, good idea to pass them in my uri, I will do that.

On my frontend i wanted to check for mobile device or not and then launch the subrequests depending on the result on the backend. But maybe it's better to reverse proxy everything and check everything directly on backend (because of the limitations you mentioned in your post)?

Yaroslav

unread,
Apr 8, 2014, 5:17:45 AM4/8/14
to nx...@googlegroups.com
I think checking for mobile in nxweb might make sense only in case you have different backends (different servers) for mobile and not mobile. Otherwise it is more simple to check for mobile on backend.


--

Andries

unread,
Apr 8, 2014, 2:56:04 PM4/8/14
to nx...@googlegroups.com
The idea was a model with mobile and desktop to different backends.

If no backend is defined for a http_proxy in the configuration file, will it determine one automatically out of the defined backend pool? Is there some kind of load balancing for the backends?

Yaroslav

unread,
Apr 8, 2014, 3:48:25 PM4/8/14
to nx...@googlegroups.com
You can write custom request dispatcher for this purpose. It can be registered by one of your modules (use NXWEB_MODULE(...)).

Your request dispatcher can inspect request before routing, re-write URL and call _nxweb_default_request_dispatcher().

This way you can redirect your request to different backends. As well as load balance them. There is no default load balancer.



On Tue, Apr 8, 2014 at 10:56 PM, Andries <andrie...@gmail.com> wrote:
The idea was a model with mobile and desktop to different backends.

If no backend is defined for a http_proxy in the configuration file, will it determine one automatically out of the defined backend pool? Is there some kind of load balancing for the backends?

--

Andries Arijs

unread,
Apr 9, 2014, 2:36:28 PM4/9/14
to nx...@googlegroups.com
I'm sorry, but can you give me an example of this? I can't find an example in the source code. For the moment, I only use on_startup and on_shutdown in my modules.


--
You received this message because you are subscribed to a topic in the Google Groups "nxweb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nxweb/tQv8eHB8Lqk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nxweb+un...@googlegroups.com.

Yaroslav

unread,
Apr 9, 2014, 2:46:21 PM4/9/14
to nx...@googlegroups.com
Something like this:

static nxweb_result my_dispatcher(nxweb_http_server_connection* conn, nxweb_http_request* req, nxweb_http_response* resp) {
    if (some_condition) {
        char* new_uri=nxb_alloc_obj(req->nxb, new_uri_len);
        memcpy(new_uri, ...);
        req->uri=new_uri;
    }
    return _nxweb_default_request_dispatcher(conn, req, resp);
}

NXWEB_MODULE(my_module, .on_server_startup=on_startup, .on_server_shutdown=on_shutdown, .request_dispatcher=my_dispatcher);


Andries Arijs

unread,
Apr 10, 2014, 3:11:41 PM4/10/14
to nx...@googlegroups.com
If I want to do some actions (fill some variables for example) on every request, is request_dispatcher then the good way? Or are there some other modules that I can register that are better for this job?

Yaroslav

unread,
Apr 10, 2014, 3:46:01 PM4/10/14
to nx...@googlegroups.com
If you want to do something on every request (for all handlers, as well as for all subrequests) then using request dispatcher seems to be appropriate. Beware that there are various kinds of requests and subrequests so be careful not to destroy request information before it reaches its handler.

If you need to store something for your handler you can use nxweb_set_request_data(), then retrieve it with nxweb_get_request_data().

If you tell me what you are trying to achieve and what kind of variables you are going to fill, then I might advise something better.

Andries Arijs

unread,
Apr 11, 2014, 7:12:28 AM4/11/14
to nx...@googlegroups.com
At the moment, I want to hold the type of device the user connects with. This works. I'm planning to let sessionid (and others) go the same way.

nxweb_set/get_request_data(), does this mean that you add a custom variable to the request (like req->myvar)?

Are there any other request besides the handlers and the subrequests? If I am correct, I can check subrequests with req->parent_req?

Yaroslav

unread,
Apr 11, 2014, 8:02:12 AM4/11/14
to nx...@googlegroups.com
On Fri, Apr 11, 2014 at 3:12 PM, Andries Arijs <andrie...@gmail.com> wrote:
At the moment, I want to hold the type of device the user connects with. This works. I'm planning to let sessionid (and others) go the same way.

nxweb_set/get_request_data(), does this mean that you add a custom variable to the request (like req->myvar)?

req->myvar requires modifying nxweb's source code, which I typically try to avoid as it complicates nxweb updates. I use set/get_request_data() myself in some modules so you can see them for example.
 

Are there any other request besides the handlers and the subrequests?

Do not forget sendfile handler requests, etc. There are also 404-not-found requests which might come from unexpected sources.
 
If I am correct, I can check subrequests with req->parent_req?

This is correct.

Andries Arijs

unread,
Apr 13, 2014, 3:30:44 AM4/13/14
to nx...@googlegroups.com
Yaroslav, is it possible to filter out sendfile requests in the request dispatcher? Can I check which handler is being executed?

Andries Arijs

unread,
Apr 13, 2014, 3:53:13 AM4/13/14
to nx...@googlegroups.com
Never mind Yaroslav, I check against req->uri.

Yaroslav

unread,
Apr 13, 2014, 3:59:11 AM4/13/14
to nx...@googlegroups.com
Yes, req->uri is the only way. Dispatcher is invoked before routing.
Reply all
Reply to author
Forward
0 new messages