Re: added support for precompressed static files on httpd(so sorry about my other email that was unreadable)
> your diff has numerous issues. What exactly do you mean by issues? Do you mean bugs? > It also seems you've either purposely broken comment blocks or > are commenting out sections of existing code. Yes i am commenting out sections of existing code, i didn't comment the code out at the start but no matter what i tried i got error code 400 I completely understand if you don't wanna accept the patch for this reason. > See https://www.openbsd.org/faq/faq5.html#Diff as well as style(9) man > page. I will, should i resubmit the patch following style(9) and the diff part of fqa? Or will it still be rejected due to commenting out existing code?
Re: added support for precompressed static files on httpd(so sorry about my other email that was unreadable)
On Sat, May 01, 2021 at 09:26:39PM +, alloca wrote: > This patch adds a serve_gzip option. When enabled, If the client requests > path, then serve path.gz if it exists and the client accepts > Content-Encoding: gzip. > > man style > diff -up httpd.orig/config.c httpd/config.c > --- httpd.orig/config.c Sat May 1 15:03:11 2021 > +++ httpd/config.c Sat May 1 15:45:43 2021 > @@ -568,12 +568,12 @@ config_getserver_config(struct httpd *env, struct serv > &parent->default_type, sizeof(struct media_type)); > } > > - f = SRVFLAG_PATH_REWRITE|SRVFLAG_NO_PATH_REWRITE; > +/* f = SRVFLAG_PATH_REWRITE|SRVFLAG_NO_PATH_REWRITE; > if ((srv_conf->flags & f) == 0) { > srv_conf->flags |= parent->flags & f; > (void)strlcpy(srv_conf->path, parent->path, > sizeof(srv_conf->path)); > - } > + } */ > > f = SRVFLAG_SERVER_HSTS; > srv_conf->flags |= parent->flags & f; > diff -up httpd.orig/httpd.conf.5 httpd/httpd.conf.5 > --- httpd.orig/httpd.conf.5 Sat May 1 15:03:11 2021 > +++ httpd/httpd.conf.5 Sat May 1 16:02:44 2021 > @@ -397,6 +397,13 @@ a browser's preload list. > Signal to the receiving user agent that this host and all sub domains > of the host's domain should be considered HSTS hosts. > .El > +.It Ic serve_gzip > +If the client requests > +.Nm path , > +then serve > +.Nm path.gz > +if it exists and the client accepts > +.Nm Content-Encoding: gzip . > .It Ic listen on Ar address Oo Ic tls Oc Ic port Ar number > Set the listen address and port. > This statement can be specified multiple times. > diff -up httpd.orig/httpd.h httpd/httpd.h > --- httpd.orig/httpd.h Sat May 1 15:03:11 2021 > +++ httpd/httpd.h Sat May 1 15:41:58 2021 > @@ -390,17 +390,17 @@ SPLAY_HEAD(client_tree, client); > #define SRVFLAG_SERVER_MATCH 0x0020 > #define SRVFLAG_SERVER_HSTS 0x0040 > #define SRVFLAG_DEFAULT_TYPE 0x0080 > -#define SRVFLAG_PATH_REWRITE 0x0100 > -#define SRVFLAG_NO_PATH_REWRITE 0x0200 > +/* #define SRVFLAG_PATH_REWRITE 0x0100 > +#define SRVFLAG_NO_PATH_REWRITE 0x0200 */ > #define SRVFLAG_LOCATION_FOUND 0x4000 > #define SRVFLAG_LOCATION_NOT_FOUND 0x8000 > - > +#define SRVFLAG_SERVER_GZIP 0x0100 > #define SRVFLAG_BITS \ > "\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX" \ > "\05ROOT\06LOCATION\07FCGI\10NO_FCGI\11LOG\12NO_LOG" \ > "\14SYSLOG\15NO_SYSLOG\16TLS\17ACCESS_LOG\20ERROR_LOG" \ > "\21AUTH\22NO_AUTH\23BLOCK\24NO_BLOCK\25LOCATION_MATCH" \ > - "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31PATH\32NO_PATH" \ > + "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31SERVER_GZIP" \ > "\37LOCATION_FOUND\40LOCATION_NOT_FOUND" > > #define TCPFLAG_NODELAY 0x01 > @@ -684,7 +684,7 @@ int server_headers(struct client *, void *, > int (*)(struct client *, struct kv *, void *), void *); > int server_writeresponse_http(struct client *); > int server_response_http(struct client *, unsigned int, > - struct media_type *, off_t, time_t); > + struct media_type *, off_t, time_t, int); > void server_reset_http(struct client *); > void server_close_http(struct client *); > int server_response(struct httpd *, struct client *); > diff -up httpd.orig/parse.y httpd/parse.y > --- httpd.orig/parse.y Sat May 1 15:03:11 2021 > +++ httpd/parse.y Sat May 1 15:48:31 2021 > @@ -138,7 +138,7 @@ typedef struct { > %token COMBINED CONNECTION DHE DIRECTORY ECDHE ERR FCGI INDEX IP KEY LIFETIME > %token LISTEN LOCATION LOG LOGDIR MATCH MAXIMUM NO NODELAY OCSP ON PORT > PREFORK > %token PROTOCOLS REQUESTS ROOT SACK SERVER SOCKET STRIP STYLE SYSLOG TCP > TICKET > -%token TIMEOUT TLS TYPE TYPES HSTS MAXAGE SUBDOMAINS DEFAULT PRELOAD REQUEST > +%token TIMEOUT TLS TYPE TYPES HSTS SERVE_GZIP MAXAGE SUBDOMAINS DEFAULT > PRELOAD REQUEST > %token ERROR INCLUDE AUTHENTICATE WITH BLOCK DROP RETURN PASS REWRITE > %token CA CLIENT CRL OPTIONAL PARAM FORWARDED FOUND NOT > %token STRING > @@ -644,6 +644,9 @@ serveroptsl : LISTEN ON STRING opttls port { > } > srv->srv_conf.flags |= SRVFLAG_SERVER_HSTS; > } > + | SERVE_GZIP { > + srv->srv_conf.flags |= SRVFLAG_SERVER_GZIP; > + } > ; > > optfound : /* empty */ { $$ = 0; } > @@ -925,23 +928,7 @@ requestflags_l : requestflags optcommanl requestflags_ > | requestflags optnl > ; > > -requestflags : REWRITE STRING { > - if (strlcpy(srv->srv_conf.path, $2, > - sizeof(srv->srv_conf.path)) >= > - sizeof(srv->srv_conf.path)) { > - yyerror("request path too long"); > - free($2); > - YYERROR; > - } > - free($2); > - srv->srv_conf.flags |= SRVFLAG_PATH_REWRITE; > - srv->srv_conf.flags &= ~SRVFLAG_NO_PATH_REWRITE; > - } > - | NO REWRITE { > - srv->srv_conf.flags |= SRVFLAG_NO_PATH_REWRITE; > - srv->srv_conf.flags &= ~SRVFLAG_PATH_REWRITE; > - } > - | STRIP NUMBER { > +requestflags : STRIP NUMBER { > if ($2 < 0 || $2 > INT_MAX) { > yyerror("invalid strip number"); > YYERROR; > @@ -1431,6 +1418,7 @@ lookup(char *s) > { "rewrite", REWRITE }, > { "root", ROOT }, > { "sack", SACK }, > + { "serve_gzip", SERVE_GZIP }, > { "server", SERVER }, > { "socket", SOCKET }, > {
added support for precompressed static files on httpd(so sorry about my other email that was unreadable)
This patch adds a serve_gzip option. When enabled, If the client requests path, then serve path.gz if it exists and the client accepts Content-Encoding: gzip. diff -up httpd.orig/config.c httpd/config.c --- httpd.orig/config.c Sat May 1 15:03:11 2021 +++ httpd/config.c Sat May 1 15:45:43 2021 @@ -568,12 +568,12 @@ config_getserver_config(struct httpd *env, struct serv &parent->default_type, sizeof(struct media_type)); } - f = SRVFLAG_PATH_REWRITE|SRVFLAG_NO_PATH_REWRITE; +/* f = SRVFLAG_PATH_REWRITE|SRVFLAG_NO_PATH_REWRITE; if ((srv_conf->flags & f) == 0) { srv_conf->flags |= parent->flags & f; (void)strlcpy(srv_conf->path, parent->path, sizeof(srv_conf->path)); - } + } */ f = SRVFLAG_SERVER_HSTS; srv_conf->flags |= parent->flags & f; diff -up httpd.orig/httpd.conf.5 httpd/httpd.conf.5 --- httpd.orig/httpd.conf.5 Sat May 1 15:03:11 2021 +++ httpd/httpd.conf.5 Sat May 1 16:02:44 2021 @@ -397,6 +397,13 @@ a browser's preload list. Signal to the receiving user agent that this host and all sub domains of the host's domain should be considered HSTS hosts. .El +.It Ic serve_gzip +If the client requests +.Nm path , +then serve +.Nm path.gz +if it exists and the client accepts +.Nm Content-Encoding: gzip . .It Ic listen on Ar address Oo Ic tls Oc Ic port Ar number Set the listen address and port. This statement can be specified multiple times. diff -up httpd.orig/httpd.h httpd/httpd.h --- httpd.orig/httpd.h Sat May 1 15:03:11 2021 +++ httpd/httpd.h Sat May 1 15:41:58 2021 @@ -390,17 +390,17 @@ SPLAY_HEAD(client_tree, client); #define SRVFLAG_SERVER_MATCH 0x0020 #define SRVFLAG_SERVER_HSTS 0x0040 #define SRVFLAG_DEFAULT_TYPE 0x0080 -#define SRVFLAG_PATH_REWRITE 0x0100 -#define SRVFLAG_NO_PATH_REWRITE 0x0200 +/* #define SRVFLAG_PATH_REWRITE 0x0100 +#define SRVFLAG_NO_PATH_REWRITE 0x0200 */ #define SRVFLAG_LOCATION_FOUND 0x4000 #define SRVFLAG_LOCATION_NOT_FOUND 0x8000 - +#define SRVFLAG_SERVER_GZIP 0x0100 #define SRVFLAG_BITS \ "\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX" \ "\05ROOT\06LOCATION\07FCGI\10NO_FCGI\11LOG\12NO_LOG" \ "\14SYSLOG\15NO_SYSLOG\16TLS\17ACCESS_LOG\20ERROR_LOG" \ "\21AUTH\22NO_AUTH\23BLOCK\24NO_BLOCK\25LOCATION_MATCH" \ - "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31PATH\32NO_PATH" \ + "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31SERVER_GZIP" \ "\37LOCATION_FOUND\40LOCATION_NOT_FOUND" #define TCPFLAG_NODELAY 0x01 @@ -684,7 +684,7 @@ int server_headers(struct client *, void *, int (*)(struct client *, struct kv *, void *), void *); int server_writeresponse_http(struct client *); int server_response_http(struct client *, unsigned int, - struct media_type *, off_t, time_t); + struct media_type *, off_t, time_t, int); void server_reset_http(struct client *); void server_close_http(struct client *); int server_response(struct httpd *, struct client *); diff -up httpd.orig/parse.y httpd/parse.y --- httpd.orig/parse.y Sat May 1 15:03:11 2021 +++ httpd/parse.y Sat May 1 15:48:31 2021 @@ -138,7 +138,7 @@ typedef struct { %token COMBINED CONNECTION DHE DIRECTORY ECDHE ERR FCGI INDEX IP KEY LIFETIME %token LISTEN LOCATION LOG LOGDIR MATCH MAXIMUM NO NODELAY OCSP ON PORT PREFORK %token PROTOCOLS REQUESTS ROOT SACK SERVER SOCKET STRIP STYLE SYSLOG TCP TICKET -%token TIMEOUT TLS TYPE TYPES HSTS MAXAGE SUBDOMAINS DEFAULT PRELOAD REQUEST +%token TIMEOUT TLS TYPE TYPES HSTS SERVE_GZIP MAXAGE SUBDOMAINS DEFAULT PRELOAD REQUEST %token ERROR INCLUDE AUTHENTICATE WITH BLOCK DROP RETURN PASS REWRITE %token CA CLIENT CRL OPTIONAL PARAM FORWARDED FOUND NOT %token STRING @@ -644,6 +644,9 @@ serveroptsl : LISTEN ON STRING opttls port { } srv->srv_conf.flags |= SRVFLAG_SERVER_HSTS; } + | SERVE_GZIP { + srv->srv_conf.flags |= SRVFLAG_SERVER_GZIP; + } ; optfound : /* empty */ { $$ = 0; } @@ -925,23 +928,7 @@ requestflags_l : requestflags optcommanl requestflags_ | requestflags optnl ; -requestflags : REWRITE STRING { - if (strlcpy(srv->srv_conf.path, $2, - sizeof(srv->srv_conf.path)) >= - sizeof(srv->srv_conf.path)) { - yyerror("request path too long"); - free($2); - YYERROR; - } - free($2); - srv->srv_conf.flags |= SRVFLAG_PATH_REWRITE; - srv->srv_conf.flags &= ~SRVFLAG_NO_PATH_REWRITE; - } - | NO REWRITE { - srv->srv_conf.flags |= SRVFLAG_NO_PATH_REWRITE; - srv->srv_conf.flags &= ~SRVFLAG_PATH_REWRITE; - } - | STRIP NUMBER { +requestflags : STRIP NUMBER { if ($2 < 0 || $2 > INT_MAX) { yyerror("invalid strip number"); YYERROR; @@ -1431,6 +1418,7 @@ lookup(char *s) { "rewrite", REWRITE }, { "root", ROOT }, { "sack", SACK }, + { "serve_gzip", SERVE_GZIP }, { "server", SERVER }, { "socket", SOCKET }, { "strip", STRIP }, diff -up httpd.orig/server_file.c httpd/server_file.c --- httpd.orig/server_file.c Sat May 1 15:03:11 2021 +++ httpd/server_file.c Sat May 1 15:40:14 2021 @@ -50,7 +50,7 @@ int server_file_modified_since(struct http_descripto int server_file_method(struct client *); int parse_range_spec(char *, size_t, struc
Re: added support for precompressed static files on httpd(so sorry about my other email that was unreadable)
alloca writes: > This patch adds a serve_gzip option. When enabled, If the client requests > path, then serve path.gz if it exists and the client accepts > Content-Encoding: gzip. While I believe I understand your objective, your diff has numerous issues. It also seems you've either purposely broken comment blocks or are commenting out sections of existing code. See https://www.openbsd.org/faq/faq5.html#Diff as well as style(9) man page. -dv