It's not much, but it's a start:
Here's the code (not counting 10 or 12 lines of infrastructure-level code):
/*
** WEBPAGE: /json
**
*/
void json_page_top(void){
Blob buf = empty_blob;
cson_value * json = NULL;
cgi_set_content_type( cson_cgi_guess_content_type(&g.csonCgi) );
json = cson_cgi_env_get_val( &g.csonCgi, 'e', 0 ); /* the $ENV vars map */
blob_zero(&buf);
cson_output_Blob( json, &buf, NULL );
cgi_set_content(&buf)/*takes ownership of the buf memory*/;
}
When visiting it with the path /json/a/b/c that generates:
Headers:
1. Cache-control:
no-cache, no-store
2. Connection:
Keep-Alive
3. Content-Encoding:
gzip
4. Content-Length:
650
5. Content-Type:
application/json; charset=utf-8
6. Date:
Fri, 09 Sep 2011 02:49:37 GMT
7. Keep-Alive:
timeout=15, max=100
8. Server:
Apache/2.2.16 (Ubuntu)
9. Vary:
Accept-Encoding
10. X-Frame-Options:
SAMEORIGIN
Content:
{
"HTTP_HOST":"whiki",
"HTTP_CONNECTION":"keep-alive",
"HTTP_USER_AGENT":"Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30
(KHTML, like Gecko) Chrome/12.0.742.124 Safari/534.30",
"HTTP_ACCEPT":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"HTTP_ACCEPT_ENCODING":"gzip,deflate,sdch",
"HTTP_ACCEPT_LANGUAGE":"en-US,en;q=0.8",
"HTTP_ACCEPT_CHARSET":"ISO-8859-1,utf-8;q=0.7,*;q=0.3",
"PATH":"/usr/local/bin:/usr/bin:/bin",
"SERVER_SIGNATURE":"<address>Apache/2.2.16 (Ubuntu) Server at whiki
Port 80</address>\n",
"SERVER_SOFTWARE":"Apache/2.2.16 (Ubuntu)",
"SERVER_NAME":"whiki",
"SERVER_ADDR":"127.0.1.1",
"SERVER_PORT":"80",
"REMOTE_ADDR":"127.0.1.1",
"DOCUMENT_ROOT":"/home/stephan/cvs/fossil/whiki/website",
"SERVER_ADMIN":"[no address given]",
"SCRIPT_FILENAME":"/home/stephan/cvs/fossil/whiki/website/cgi-bin/fossil.cgi",
"REMOTE_PORT":"52331",
"GATEWAY_INTERFACE":"CGI/1.1",
"SERVER_PROTOCOL":"HTTP/1.1",
"REQUEST_METHOD":"GET",
"QUERY_STRING":"",
"REQUEST_URI":"/cgi-bin/fossil.cgi/json/a/b/c",
"SCRIPT_NAME":"/cgi-bin/fossil.cgi",
"PATH_INFO":"/json/a/b/c",
"PATH_TRANSLATED":"/home/stephan/cvs/fossil/whiki/website/json/a/b/c",
"PATH_INFO_SPLIT":[
"json",
"a",
"b",
"c"
]
}
i might have to fight with fossil a bit over who gets to parse the POST data
from stdin, since fossil will, by default, consume stdin before the JSON CGI
bits get the chance to (and if they do it first then Fossil can't do it).
But i don't need to solve that until i write a request type which needs
POST, so that can wait.
--
----- stephan beal
http://wanderinghorse.net/home/stephan/
_______________________________________________
fossil-users mailing list
[email protected]
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users