You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Roy T. Fielding" <fi...@kiwi.ICS.UCI.EDU> on 1996/11/30 13:43:29 UTC
SuppressHTMLPreamble fix/feature
Two people have asked for this change this month, and I've wanted it for
a long time, so I went ahead and coded it for 1.2b0 along the lines
suggested by Andrey A. Chernov (ache@nagual.ru), but using better code IMHO.
In his words:
>Situation:
>It is impossible to suppress initial HTML preamble for directories, i.e.
><HEAD><TITLE>Index of dir</TITLE></HEAD><BODY>
>It means that it is impossible to change <TITLE> or add any
><META HTTP-EQUIV...> tags to <HEAD> section or change <BODY>
>attributes without HTML syntax violation (.asis, cern_meta, etc.
>not helps here too).
>
>Fix:
>I add "SuppressHTMLPreamble" option to "IndexOptions". When this option
>is set _and_ HEADER.html (or what you set as it) is present and readable,
>standard <HEAD><TITLE>Index of dir</TITLE></HEAD><BODY> preamble
>will be suppressed [with the assumption being that] you have right HTML
>preamble in your HEADER.html. It solves all problems mentioned above.
Here is the patch. I have always considered this a bug, which is why
I want to commit it even with the feature freeze. I will also supply the
documentation when (if) I do the commit. +1 anybody?
BTW, I also noticed that we can't add/remove IndexOptions with the +/-
prefix like we now can with Options. This seems inconsistent to me.
Also, we should update all the copyright lines for 1996 before 1.2b1.
.....Roy
Index: mod_dir.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_dir.c,v
retrieving revision 1.16
diff -c -r1.16 mod_dir.c
*** mod_dir.c 1996/11/28 17:26:29 1.16
--- mod_dir.c 1996/11/30 12:17:24
***************
*** 1,5 ****
/* ====================================================================
! * Copyright (c) 1995 The Apache Group. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
--- 1,5 ----
/* ====================================================================
! * Copyright (c) 1995, 1996 The Apache Group. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
***************
*** 56,62 ****
* Rob McCool
* 3/23/93
*
! * Adapted to Apache by rst.
*/
#include "httpd.h"
--- 56,63 ----
* Rob McCool
* 3/23/93
*
! * Adapted to Apache by Robert S. Thau
! * Many changes by the Apache Group
*/
#include "httpd.h"
***************
*** 81,86 ****
--- 82,88 ----
#define SUPPRESS_LAST_MOD 8
#define SUPPRESS_SIZE 16
#define SUPPRESS_DESC 32
+ #define SUPPRESS_HTML_PREAMBLE 64
struct item {
char *type;
***************
*** 203,208 ****
--- 205,212 ----
opts |= SUPPRESS_SIZE;
else if(!strcasecmp(w,"SuppressDescription"))
opts |= SUPPRESS_DESC;
+ else if(!strcasecmp(w,"SuppressHTMLPreamble"))
+ opts |= SUPPRESS_HTML_PREAMBLE;
else if(!strcasecmp(w,"None"))
opts = 0;
else
***************
*** 403,409 ****
*/
! int insert_readme(char *name, char *readme_fname, int rule, request_rec *r) {
char *fn;
FILE *f;
struct stat finfo;
--- 407,433 ----
*/
! static void html_preamble(request_rec *r, const int do_heading)
! {
! char *title_name = escape_html(r->pool, r->uri);
! char *title_endp;
!
! title_endp = title_name + strlen(title_name) - 1;
!
! while (title_endp > title_name && *title_endp == '/')
! *title_endp-- = '\0';
!
! rvputs(r, "<HTML><HEAD>\n", "<TITLE>Index of ", title_name, "</TITLE>\n",
! "</HEAD><BODY>\n", NULL);
!
! if (do_heading)
! rvputs(r, "<H1>Index of ", title_name, "</H1>\n", NULL);
! }
!
!
! int insert_readme(char *name, char *readme_fname, int rule,
! int suppress_preamble, request_rec *r)
! {
char *fn;
FILE *f;
struct stat finfo;
***************
*** 417,434 ****
if(stat(fn,&finfo) == -1)
return 0;
plaintext=1;
- if(rule) rputs("<HR>\n", r);
- rputs("<PRE>\n", r);
}
- else if (rule) rputs("<HR>\n", r);
if(!(f = pfopen(r->pool,fn,"r")))
return 0;
! if (!plaintext)
send_fd(f, r);
! else
! {
char buf[IOBUFSIZE+1];
int i, n, c, ch;
while (!feof(f))
{
do n = fread(buf, sizeof(char), IOBUFSIZE, f);
--- 441,468 ----
if(stat(fn,&finfo) == -1)
return 0;
plaintext=1;
}
if(!(f = pfopen(r->pool,fn,"r")))
return 0;
! if (!plaintext) {
! if (rule)
! rputs("<HR>\n", r); /* README.html file, send separator */
! else if (!suppress_preamble)
! html_preamble(r, 0); /* HEADER.html file, send preamble */
!
send_fd(f, r);
! }
! else {
char buf[IOBUFSIZE+1];
int i, n, c, ch;
+
+ if (rule)
+ rputs("<HR>\n", r); /* README.txt file, send separator */
+ else
+ html_preamble(r, 0); /* HEADER.txt file, send preamble */
+
+ rputs("<PRE>\n", r);
+
while (!feof(f))
{
do n = fread(buf, sizeof(char), IOBUFSIZE, f);
***************
*** 449,458 ****
c = i + 1;
}
}
}
pfclose(r->pool, f);
- if(plaintext)
- rputs("</PRE>\n", r);
return 1;
}
--- 483,491 ----
c = i + 1;
}
}
+ rputs("</PRE>\n", r);
}
pfclose(r->pool, f);
return 1;
}
***************
*** 572,578 ****
if(name[0] == '\0') name = "/";
if(dir_opts & FANCY_INDEXING) {
! rputs("<PRE>", r);
if((tp = find_default_icon(d,"^^BLANKICON^^")))
rvputs(r, "<IMG SRC=\"", escape_html(scratch, tp),
"\" ALT=\" \"> ", NULL);
--- 605,611 ----
if(name[0] == '\0') name = "/";
if(dir_opts & FANCY_INDEXING) {
! rputs("<PRE>\n", r);
if((tp = find_default_icon(d,"^^BLANKICON^^")))
rvputs(r, "<IMG SRC=\"", escape_html(scratch, tp),
"\" ALT=\" \"> ", NULL);
***************
*** 665,674 ****
rputc('\n', r);
}
if(dir_opts & FANCY_INDEXING) {
! rputs("</PRE>", r);
}
else {
! rputs("</UL>", r);
}
}
--- 698,707 ----
rputc('\n', r);
}
if(dir_opts & FANCY_INDEXING) {
! rputs("</PRE>\n", r);
}
else {
! rputs("</UL>\n", r);
}
}
***************
*** 681,690 ****
int index_directory(request_rec *r, dir_config_rec *dir_conf)
{
- char *title_name = escape_html(r->pool, r->uri);
- char *title_endp;
char *name = r->filename;
-
DIR *d;
struct DIR_TYPE *dstruct;
int num_ent=0,x;
--- 714,720 ----
***************
*** 705,722 ****
return 0;
}
! /* Spew HTML preamble */
!
! title_endp = title_name + strlen(title_name) - 1;
!
! while (title_endp > title_name && *title_endp == '/')
! *title_endp-- = '\0';
! rvputs(r, "<HEAD><TITLE>Index of ", title_name, "</TITLE></HEAD><BODY>\n",
! NULL);
!
! if((!(tmp = find_header(dir_conf,r))) || (!(insert_readme(name,tmp,0,r))))
! rvputs(r, "<H1>Index of ", title_name, "</H1>\n", NULL);
/*
* Since we don't know how many dir. entries there are, put them into a
--- 735,745 ----
return 0;
}
! /* Spew HTML preamble and/or HEADER file */
! if (!((tmp = find_header(dir_conf, r)) &&
! insert_readme(name,tmp,0,(dir_opts & SUPPRESS_HTML_PREAMBLE),r)))
! html_preamble(r, 1);
/*
* Since we don't know how many dir. entries there are, put them into a
***************
*** 751,762 ****
if (dir_opts & FANCY_INDEXING)
if((tmp = find_readme(dir_conf, r)))
! insert_readme(name,tmp,1,r);
else {
rputs("</UL>", r);
}
! rputs("</BODY>", r);
return 0;
}
--- 774,785 ----
if (dir_opts & FANCY_INDEXING)
if((tmp = find_readme(dir_conf, r)))
! insert_readme(name,tmp,1,1,r);
else {
rputs("</UL>", r);
}
! rputs("</BODY></HTML>\n", r);
return 0;
}
Re: SuppressHTMLPreamble fix/feature
Posted by Brian Behlendorf <br...@organic.com>.
I agree with Alexei. Let's put this in /contrib/patches.
Brian
On Sat, 30 Nov 1996, Alexei Kosut wrote:
> On Sat, 30 Nov 1996, Roy T. Fielding wrote:
>
> > Two people have asked for this change this month, and I've wanted it for
> > a long time, so I went ahead and coded it for 1.2b0 along the lines
> > suggested by Andrey A. Chernov (ache@nagual.ru), but using better code IMHO.
> > In his words:
>
> [...]
>
> > Here is the patch. I have always considered this a bug, which is why
> > I want to commit it even with the feature freeze. I will also supply the
> > documentation when (if) I do the commit. +1 anybody?
>
> Hmm. I'm not going to -1 it, but it seems a bit too much of a feature
> for my taste. Also, the *Options directives really should be
> depreciated, since we now (and have since 0.8.0) have the ability to
> put any arbirtary directive anywhere (which we didn't have with the
> NCSA-based code, which explains the Options/IndexOptions directives in
> the first place). In otherwords, I'd perfer a "SupressHTMLPreamble
> On|Off" directive or whatnot.
--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--
brian@organic.com www.apache.org hyperreal.com http://www.organic.com/JOBS
Re: SuppressHTMLPreamble fix/feature
Posted by Alexei Kosut <ak...@nueva.pvt.k12.ca.us>.
On Sat, 30 Nov 1996, Roy T. Fielding wrote:
> Two people have asked for this change this month, and I've wanted it for
> a long time, so I went ahead and coded it for 1.2b0 along the lines
> suggested by Andrey A. Chernov (ache@nagual.ru), but using better code IMHO.
> In his words:
[...]
> Here is the patch. I have always considered this a bug, which is why
> I want to commit it even with the feature freeze. I will also supply the
> documentation when (if) I do the commit. +1 anybody?
Hmm. I'm not going to -1 it, but it seems a bit too much of a feature
for my taste. Also, the *Options directives really should be
depreciated, since we now (and have since 0.8.0) have the ability to
put any arbirtary directive anywhere (which we didn't have with the
NCSA-based code, which explains the Options/IndexOptions directives in
the first place). In otherwords, I'd perfer a "SupressHTMLPreamble
On|Off" directive or whatnot.
> BTW, I also noticed that we can't add/remove IndexOptions with the +/-
> prefix like we now can with Options. This seems inconsistent to me.
Apache is often inconsistent :)
> Also, we should update all the copyright lines for 1996 before 1.2b1.
Actually, I looked up U.S. copyright law on this a few months ago,
because I was thinking the same thing.... it turns out that it's very
vauge on the subject, and as near as I can tell, depending on
interpretation, we could put either 1995 (on the theory that the
source file is one work written from 1995 through 1996 - in this case,
the earlier date gets it), 1995-1996 (on the theory that it is two
seperate works, one written in 1995, and an addition/revision in
1996), or 1996 (on the theory that it is a new edition of the file,
done in 1996). In other words, it really doesn't matter.
--
________________________________________________________________________
Alexei Kosut <ak...@nueva.pvt.k12.ca.us> The Apache HTTP Server
URL: http://www.nueva.pvt.k12.ca.us/~akosut/ http://www.apache.org/