Re: error url

Jay C. Weber (weber@eit.COM)
Tue, 23 Aug 1994 22:02:13 +0200

I tweaked NCSA HTTPD 1.3 to support an "ErrorDocument" configuration
directive that maps error codes to virtual paths, e.g.

ErrorDocument 404 /help/404.html

means that the document returned with a "Not Found" server response is
determined by "/help/404.html". The HTTP response line is not affected.

Patches are attached for those interested.

Jay

------- cut here -------
diff httpd_1.3/src/http_config.c pacifica/src/http_config.c
35a36,38
> #define MAX_ERROR_REDIRECTS 32
> char *ealiassv[MAX_ERROR_REDIRECTS];
> int ealiasnv[MAX_ERROR_REDIRECTS], ealiasc;
52a56,67
> #ifdef PACIFICA
> {
> struct stat buf;
> extern char *httpd_bin;
>
> if (stat(httpd_bin, &buf) == 0) {
> user_id = buf.st_uid;
> group_id = buf.st_gid;
> }
> else user_id = group_id = 0;
> }
> #else
54a70
> #endif
272a289
> ealiasc = 0;
359a377,393
> #ifdef PACIFICA
> else if(!strcasecmp(w,"ErrorDocument")) {
> int atoi(char *);
> char w2[MAX_STRING_LEN];
>
> cfg_getword(w,l);
> cfg_getword(w2,l);
> if(((ealiasnv[ealiasc]=atoi(w)) < 100) || (w2[0] == '\0')) {
> fprintf(errors,"Syntax error on line %d of %s:\n",n,
> srm_confname);
> fprintf(errors,
> "ErrorDocument must be followed by a result code, one space, then a document name.\n");
> exit(1);
> }
> strcpy(ealiassv[ealiasc++] = malloc(strlen(w2)+1), w2);
> }
> #endif
diff httpd_1.3/src/http_log.c pacifica/src/http_log.c
225a226
> #ifndef PACIFICA
226a228
> #endif
244a247,265
> #ifdef PACIFICA
> int error_alias(int code, FILE *fd) {
> extern int ealiasnv[], ealiasc;
> extern char *ealiassv[];
> int i;
> static int beenhere=0;
>
> if (beenhere++) return 0;
> for (i=0; i<ealiasc; i++)
> if (ealiasnv[i] == code) {
> fprintf(fd, "Error-document-response: ");
> fflush(fd);
> fullfill_request("GET", ealiassv[i], "", 0, fd);
> return 1;
> }
> return 0;
> }
> #endif
>
254a276,279
> #ifdef PACIFICA
> if (error_alias(status, fd)) break;
> dump_default_header(fd);
> #endif
260a286
> fprintf(fd,"</BODY>%c",LF);
264a291,294
> #ifdef PACIFICA
> if (error_alias(status, fd)) break;
> dump_default_header(fd);
> #endif
272a303,308
> #ifdef PACIFICA
> fprintf(fd,"WWW-Authenticate: %s%c",err_string,LF);
> if (error_alias(status, fd)) break;
> dump_default_header(fd);
> fputc(LF,fd);
> #else
273a310
> #endif
278a316
> fprintf(fd,"</BODY>%c",LF);
281a320,326
> #ifdef PACIFICA
> begin_http_header(fd,"400 Bad Request");
> if (error_alias(status, fd)) break;
> dump_default_header(fd);
> fputc(LF,fd);
> title_html(fd,"400 Bad Request");
> #else
282a328
> #endif
286a333
> fprintf(fd,"</BODY>%c",LF);
289a337,343
> #ifdef PACIFICA
> begin_http_header(fd,"403 Forbidden");
> if (error_alias(status, fd)) break;
> dump_default_header(fd);
> fputc(LF,fd);
> title_html(fd,"403 Forbidden");
> #else
290a345
> #endif
294a350
> fprintf(fd,"</BODY>%c",LF);
297a354,360
> #ifdef PACIFICA
> begin_http_header(fd,"404 Not Found");
> if (error_alias(status, fd)) break;
> dump_default_header(fd);
> fputc(LF,fd);
> title_html(fd,"404 Not Found");
> #else
298a362
> #endif
301a366
> fprintf(fd,"</BODY>%c",LF);
304a370,377
> #ifdef PACIFICA
> log_error(err_string);
> begin_http_header(fd,"500 Server Error");
> if (error_alias(status, fd)) break;
> dump_default_header(fd);
> fputc(LF,fd);
> title_html(fd,"500 Server Error");
> #else
306a380
> #endif
308c382
< break;

---
> 	  break;
316a391
> 	fprintf(fd,"</BODY>%c",LF);
319a395,401
> #ifdef PACIFICA
> 	begin_http_header(fd,"501 Not Implemented");
> 	if (error_alias(status, fd)) break;
> 	dump_default_header(fd);
> 	fputc(LF,fd);
>         title_html(fd,"501 Not Implemented");
> #else
320a403
> #endif
329a413
> 	fprintf(fd,"</BODY>%c",LF);
333a418,424
> #ifdef PACIFICA
> 	begin_http_header(fd,"500 Server Error");
> 	if (error_alias(status, fd)) break;
> 	dump_default_header(fd);
> 	fputc(LF,fd);
>         title_html(fd,"500 Server Error");
> #else
334a426
> #endif
337a430
> 	fprintf(fd,"</BODY>%c",LF);
340,341d432
<     if(!header_only)
<         fprintf(fd,"</BODY>%c",LF);