Returns HTTP error if some error has been found while serving the file.
authorThadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
Sun, 27 Jan 2008 04:43:24 +0000 (02:43 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
Sun, 27 Jan 2008 04:43:24 +0000 (02:43 -0200)
frontend/cgi/cgi.c

index 6403273..3ebd3a0 100644 (file)
@@ -39,6 +39,7 @@ cgi_serve_request (AtomCtx *ctx)
     {
       IRI *iri = iri_new ();
       Atom *atom;
+      GError *error;
       iri_set_path (iri, path);
       atom = atom_retrieve_resource (ctx, iri);
       iri_delete (iri);
@@ -49,6 +50,19 @@ cgi_serve_request (AtomCtx *ctx)
          write (1, atom_string (atom), atom_len (atom));
          atom_delete (atom);
        }
+      else if ((error = atom_error_get (ctx)) != NULL)
+       {
+         if (error->domain == G_FILE_ERROR &&
+             (error->code == G_FILE_ERROR_EXIST ||
+              error->code == G_FILE_ERROR_ACCESS ||
+              error->code == G_FILE_ERROR_PERM))
+           fprintf (stdout, "Status: 403 %s\n\n", err->message);
+         else if (error->domain == G_FILE_ERROR &&
+                  error->code == G_FILE_ERROR_NOENT)
+           fprintf (stdout, "Status: 404 %s\n\n", err->message);
+         else
+           fprintf (stdout, "Status: 500 %s\n\n", err->message);
+       }
     }
   else
     {