summaryrefslogtreecommitdiff
path: root/src/config/lexparse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config/lexparse.c')
-rw-r--r--src/config/lexparse.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/config/lexparse.c b/src/config/lexparse.c
index 27a62df..783e39f 100644
--- a/src/config/lexparse.c
+++ b/src/config/lexparse.c
@@ -45,6 +45,7 @@ enum token_e
T_GLOBAL,
T_LOG,
T_CONTENTTYPE,
+ T_CUSTOMHEADER,
T_DOMAIN,
T_NPHPREFIX,
T_REDIRECT,
@@ -195,6 +196,27 @@ static inline void parse_contenttype (char const *s, size_t const *word, size_t
}
}
+static inline void parse_customheader (char const *s, size_t const *word, size_t n, mdt const *md)
+{
+ uint8_t options = 0 ;
+ if (n < 3)
+ strerr_dief8x(1, "too ", "few", " arguments to directive ", "custom-header", " in file ", g.storage.s + md->filepos, " line ", md->linefmt) ;
+ if (!strcmp(s + word[0], "weak")) options |= 1 ;
+ else if (!strcmp(s + word[0], "strong")) options &= ~1 ;
+ else strerr_dief7x(1, "type should be weak or strong for", " directive ", "custom-header", " in file ", g.storage.s + md->filepos, " line ", md->linefmt) ;
+ word++ ; n-- ;
+ {
+ size_t len = strlen(s + *word) ;
+ char key[len + 1] ;
+ memcpy(key, s + *word++, len + 1) ; n-- ;
+ header_canonicalize(key) ;
+ if (!header_allowed(key))
+ strerr_dief7x(1, "header ", key, " cannot be customized", " in file ", g.storage.s + md->filepos, " line ", md->linefmt) ;
+ headers_checkunique(key, md) ;
+ headers_addv(key, options, s, word, n, md->filepos, md->line) ;
+ }
+}
+
static inline void parse_redirect (char const *s, size_t const *word, size_t n, char const *domain, size_t domainlen, mdt const *md)
{
static uint32_t const codes[4] = { 307, 308, 302, 301 } ;
@@ -360,6 +382,7 @@ static inline void process_line (char const *s, size_t const *word, size_t n, st
{ .s = "basic-auth", .token = T_BASICAUTH },
{ .s = "cgi", .token = T_CGI },
{ .s = "content-type", .token = T_CONTENTTYPE },
+ { .s = "custom-header", .token = T_CUSTOMHEADER },
{ .s = "custom-response", .token = T_CUSTOMRESPONSE },
{ .s = "domain", .token = T_DOMAIN },
{ .s = "file-type", .token = T_FILETYPE },
@@ -404,6 +427,9 @@ static inline void process_line (char const *s, size_t const *word, size_t n, st
case T_CONTENTTYPE :
parse_contenttype(s, word, n, md) ;
break ;
+ case T_CUSTOMHEADER :
+ parse_customheader(s, word, n, md) ;
+ break ;
case T_DOMAIN :
if (n != 1)
strerr_dief8x(1, "too ", n > 1 ? "many" : "few", " arguments to directive ", "domain", " in file ", g.storage.s + md->filepos, " line ", md->linefmt) ;
@@ -518,4 +544,5 @@ void conf_lexparse (buffer *b, char const *ifile)
stralloc_free(&domain) ;
genalloc_free(size_t, &words) ;
stralloc_free(&sa) ;
+ headers_finish() ;
}