NetBurner 3.3
Creating a GET Request Handler

There are two common methods for moving data from the client web browser to the web server on an embedded platform: HTML Forms using POST, and storing the data in the URL. For example, an e-commerce applications might store product information such as: , which is storing the data type=order123 in the URL. Everything following the ‘?’ character is ignored by the browser, so your application can store whatever data it needs after the character. One advantage of this method is that the application is stateful, meaning multiple users can access the same application and each user’s session maintains its specific data in the URL.

When a web browser requests something from a web server, such as an HTML page or image, it makes a GET request. The web server normally handles static web pages and dynamic web pages with the CPPCALL and VARIABLE tags, but your application can intercept the request and take control of the processing using a callback function object called CallBackFunctionPageHandler. When you declare the instance of the object you specify the name of the request to intercept and a pointer to the function in your application to process the request. For example, to take control of processing for a HTML page named setcookie.html:

int setCookieGetReqCallback( int sock, HTTP_Request &httpRequestInfo )
iprintf( "HTTP request: %s\r\n", httpRequestInfo.pURL );
// Set the cookie value to "MyCookie ". Note that you need a trailing space.
SendHTMLHeaderWCookie(sock, "MyCookie ");
// Since we are handling the GET request, we need to send the web page
SendFileFragment("setcookie.html", sock);
return 1; // Notify the system GET handler we handled the request
"setcookie.html", // Web page to intercept
setCookieGetReqCallback, // Pointer to callback function
tGet, // Type of request, GET
0, // Password level, none
true ); // Take responsibility for entire response, the web
// server will not send any data of its own

A callback function can be created for any type of URL request. If you application has the ability to create a graph or image named TempGraph.gif, you could use a callback for TempGraph.gif instead of setcookie.html in the above example. There are examples in the \nburn\examples\web directory. You can also use the ‘*’ as a wild card for matching a number of pages to process in a single callback. For example, to process all requests that begin with “set”, specify “set*”.

void SendHTMLHeaderWCookie(int sock, char *cookie)
Send a HTML response header and cookie.
Definition: httpinternal.cpp:266
@ tGet
GET request.
Definition: http.h:27
Implements the HtmlPageHandler class as a function pointer callback for GET requests.
Definition: http.h:158
Request URL.
Definition: http.h:61
HTTP Request Structure.
Definition: http.h:60
int32_t SendFileFragment(char const *name, int32_t fd, PCSTR url=NULL)
Send a file fragment without a header.
Definition: htmldecomp.cpp:347