Page 1 of 1

SetNewGetHandler return value

Posted: Thu Apr 18, 2013 9:01 am
by seulater
When we need a custom handler we use SetNewGetHandler.
Typically like this (see below).
My question is what is the return value used for ?


static http_gethandler * oldhand;
oldhand = SetNewGetHandler( MyDoGet );

/*-------------------------------------------------------------------
Override GET requests to the web server
Parameters:
sock = Handle to open socket connection from client
url = URL client used to get here
rxBuffer = Pointer to the complete HTTP request
------------------------------------------------------------------*/
int MyDoGet( int sock, PSTR url, PSTR rxBuffer )
{

return 0;
}

Re: SetNewGetHandler return value

Posted: Thu Apr 18, 2013 9:33 am
by dciliske
So, say you need to handle a specific path/page/etc. in a special way, but most of the time you just want to serve the page that's at the target path. The normal handler will handle that, if you use it as a fall through. The return value is to allow this chaining.

Re: SetNewGetHandler return value

Posted: Thu Apr 18, 2013 9:37 am
by seulater
I have seen examples with return 0 and return 1 and also return ( *oldhand ) ( sock, url, rxBuffer );
so i became curious about the differences between them.

Re: SetNewGetHandler return value

Posted: Thu Apr 18, 2013 10:01 am
by dciliske
Er, can you clarify which function you're asking about the return value from? Is it SetNewGetHandler or MyDoGet?

Re: SetNewGetHandler return value

Posted: Thu Apr 18, 2013 10:06 am
by seulater
Sorry, MyDoGet.

Re: SetNewGetHandler return value

Posted: Tue Nov 12, 2013 12:51 am
by roland.ames
Still no answer to the question

How is the MyDoGet return value interpreted??

Re: SetNewGetHandler return value

Posted: Tue Nov 12, 2013 9:19 am
by dciliske
Hmm... This isn't like me to leave a question unanswered. Anyways, the reason for the return value is once upon a time it was requested that the get handler have the ability to not close the socket when it finished (like transferring a 500MB file using a secondary task). The return value determines what to do. In the event that the get handler returns 2, the webserver will not terminate the connection, with the understanding that the socket is now owned by a different task. And no, I don't know why 2 was chosen and/or why this wasn't documented. 0 and 1 appear to have, once upon a time, been used in internal diagnostics, but are as of now unused.

Hope that clears up some of the confusion. :/

-Dan

Re: SetNewGetHandler return value

Posted: Wed Nov 13, 2013 11:18 pm
by roland.ames
Thanks Dan.