0

I picked up G-WAN only a while back and I'm trying to figure out how to make the index use a specific servlet while also having static content available.

I moved index.html to index_old.html so I wouldn't have any conflicts.

I placed the following into a handler.

xbuf_t *read_xbuf = (xbuf_t*)get_env(argv, READ_XBUF);
xbuf_replfrto(read_xbuf, read_xbuf->ptr, read_xbuf->ptr + 16, "/", "/?hello");

After restarting gwan, I saw Hello, ANSI C! just like I desired.

However, I noticed that all other contents no longer loaded, even the 404 page was different!

So, then I had a thought, that this seemed to be doing string substitution, rather than precise matching.

xbuf_t *read_xbuf = (xbuf_t*)get_env(argv, READ_XBUF);
xbuf_replfrto(read_xbuf, read_xbuf->ptr, read_xbuf->ptr + 16, "/", "/?");

Now, when hitting /, I saw a 404, and /hello, I saw the servlet again. So, this does not seem to be the solution I am looking for.

Again, I just want / to hit a specific servlet of my designation, and for all other requests to not be effected by this one rule.

Thanks,

Levi Schuck
  • 59
  • 2
  • 8

1 Answers1

0

It appears that a similar solution is presented in G-WAN handler rewriting solution

Using that, I derived the following code that allows not only the index to be generated, but also any additional query strings.

char *szRequest = (char*)get_env(argv, REQUEST);
if(strncmp(szRequest, "GET / ", 6) == 0){
        xbuf_t *read_xbuf = (xbuf_t*)get_env(argv, READ_XBUF);
        xbuf_replfrto(read_xbuf, read_xbuf->ptr, read_xbuf->ptr + 16, "/", "/!hello");
}else if(strncmp(szRequest, "GET /?", 6) == 0){
        xbuf_t *read_xbuf = (xbuf_t*)get_env(argv, READ_XBUF);
        xbuf_replfrto(read_xbuf, read_xbuf->ptr, read_xbuf->ptr + 16, "/?", "/!hello&");
}

As seen above, I had to move to ! to avoid conflict. This means I had to add the following in the init() function.

u8 *query_char = (u8*)get_env(argv, QUERY_CHAR);
*query_char = '!'; 

I am able to access / and /?blah without issue, while still being able to access a file like 100.html without getting a servlet 404.

It seems like any other similar bindings to a URL while not blocking off the rest of the directory can be made easier with a macro.

Community
  • 1
  • 1
Levi Schuck
  • 59
  • 2
  • 8