implement action=raw which sends just the data-blob
authorChristian Thaeter <ct@pipapo.org>
Tue, 8 Jan 2008 05:53:34 +0000 (06:53 +0100)
committerChristian Thaeter <ct@pipapo.org>
Tue, 8 Jan 2008 05:53:34 +0000 (06:53 +0100)
src/actions.c
src/webgit.c

index 6ce5472..f60b444 100644 (file)
@@ -200,12 +200,26 @@ webgit_tree_action (struct webgit_query* query)
 
 
 /*
-  spew out raw data only
+  spew out raw data
 */
 static Html
 webgit_raw_action (struct webgit_query* query)
 {
-  return html("raw");
+  webgit_enter_repository (query);
+
+  unsigned char sha1[20];
+  if (get_sha1 (query->object, sha1))
+    return html("error: unknown object");
+
+  void* buf;
+  unsigned long size;
+
+  buf = read_object_with_reference (sha1, "blob", &size, NULL);
+
+  free (query->content_type);
+  query->content_type = webgit_mimetype (query->path);
+
+  return html_binary (buf, size);
 }
 
 
index 5fe7484..43795b8 100644 (file)
@@ -181,59 +181,79 @@ main (int argc, char**argv)
   // query to cache-line
 
   // check if in cache
-  
+
   // generate page
-  
-  //Html page = webgit_action_dispatch (&query);
 
-  page = html(
-              html_httpheader(
-                              html_httpfield(
-                                             "Content-type",
-                                             query.content_type,
-                                             html_attr("charset", "UTF-8")
-                                             )//,
-                              //html_httpfield("Last-Modified", cgit_page.modified),
-                              //html_httpfield("Expires", cgit_page.expires)
-                              ),
-              html_document(
-                            "-//W3C//DTD XHTML 1.0 Transitional//EN",
-                            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
-                            html_content(
-                                         /*head*/
-                                         html(
-                                              html(html_tag("title"), "webgit"),
-                                              html_nl(),
-                                              html_meta("generator", "webgit")//,
-                                              //html_link_rel("stylesheet", "text/css", cgit_page.stylesheet)
-                                              ),
-                                         /*body*/
-                                         html (
-                                               html (
-                                                     html_tag("div"),
-                                                     webgit_action_dispatch (&query)
-                                                     ),
-                                               html(
-                                                    html_tag("div"),
-                                                    error_log
-                                                    )
-                                         ),
-                                         html_attr("xmlns", "http://www.w3.org/1999/xhtml"),
-                                         html_attr("xml:lang", "en"),
-                                         html_attr("lang", "en")
+  Html content = webgit_action_dispatch (&query);
+
+  if (query.content_type && !strcmp (query.content_type, "text/html"))
+    {
+      /* generate html page */
+      page = html(
+                  html_httpheader(
+                                  html_httpfield(
+                                                 "Content-type",
+                                                 query.content_type,
+                                                 html_attr("charset", "UTF-8")
+                                                 )//,
+                                  //html_httpfield("Last-Modified", cgit_page.modified),
+                                  //html_httpfield("Expires", cgit_page.expires)
+                                  ),
+                  html_document(
+                                "-//W3C//DTD XHTML 1.0 Transitional//EN",
+                                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
+                                html_content(
+                                             /*head*/
+                                             html(
+                                                  html(html_tag("title"), "webgit"),
+                                                  html_nl(),
+                                                  html_meta("generator", "webgit")//,
+                                                  //html_link_rel("stylesheet", "text/css", cgit_page.stylesheet)
+                                                  ),
+                                             /*body*/
+                                             html (
+                                                   html (
+                                                         html_tag("div"),
+                                                         content
+                                                         ),
+                                                   html(
+                                                        html_tag("div"),
+                                                        error_log
+                                                        )
+                                                   ),
+                                             html_attr("xmlns", "http://www.w3.org/1999/xhtml"),
+                                             html_attr("xml:lang", "en"),
+                                             html_attr("lang", "en")
+                                             )
+                                )
+                  );
+
+      timestat = clock() - timestat;
+      html_list_append (error_log, html (
+                                         html_fmt ("processing took %g secs\n", timestat/(float)CLOCKS_PER_SEC),
+                                         html_tag("br")
                                          )
-                            )
-              );
+                        );
 
-  timestat = clock() - timestat;
-  html_list_append (error_log, html (
-                                     html_fmt ("processing took %g secs\n", timestat/(float)CLOCKS_PER_SEC),
-                                     html_tag("br")
-                                     )
-                    );
 
-  html_fprint (stdout, page);
+    }
+  else
+    {
+      /* diffrent content type, raw content */
+      html_free (error_log);
+
+      page = html(
+                  html_httpheader (
+                                   html_httpfield ("Content-type",
+                                                   query.content_type ?
+                                                   query.content_type
+                                                   : "application/octet-stream")
+                                  ),
+                  content
+                  );
+    }
 
+  html_fprint (stdout, page);
 
   html_free (page);