Created
March 4, 2017 09:03
-
-
Save yannick/b4a2b3b25879df79142ab5526913239e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/lib/core/logconf.c b/lib/core/logconf.c | |
| index 1f8b30d8..b1b85e4f 100644 | |
| --- a/lib/core/logconf.c | |
| +++ b/lib/core/logconf.c | |
| @@ -34,6 +34,7 @@ enum { | |
| ELEMENT_TYPE_METHOD, /* %m */ | |
| ELEMENT_TYPE_LOCAL_PORT, /* %p, %{local}p */ | |
| ELEMENT_TYPE_REMOTE_PORT, /* %{remote}p */ | |
| + ELEMENT_TYPE_ENV_VAR, /* %{..}e */ | |
| ELEMENT_TYPE_QUERY, /* %q */ | |
| ELEMENT_TYPE_REQUEST_LINE, /* %r */ | |
| ELEMENT_TYPE_STATUS, /* %s */ | |
| @@ -150,6 +151,13 @@ h2o_logconf_t *h2o_logconf_compile(const char *fmt, int escape, char *errbuf) | |
| goto Error; | |
| } | |
| break; | |
| + case 'e': | |
| + { | |
| + h2o_iovec_t name = h2o_strdup(NULL, pt, quote_end - pt); | |
| + NEW_ELEMENT(ELEMENT_TYPE_ENV_VAR); | |
| + LAST_ELEMENT()->data.name = name; | |
| + } | |
| + break; | |
| case 't': | |
| if (h2o_memis(pt, quote_end - pt, H2O_STRLIT("sec"))) { | |
| NEW_ELEMENT(ELEMENT_TYPE_TIMESTAMP_SEC_SINCE_EPOCH); | |
| @@ -213,7 +221,7 @@ h2o_logconf_t *h2o_logconf_compile(const char *fmt, int escape, char *errbuf) | |
| #undef MAP_EXT_TO_PROTO | |
| break; | |
| default: | |
| - sprintf(errbuf, "failed to compile log format: header name is not followed by either `i`, `o`, `x`"); | |
| + sprintf(errbuf, "failed to compile log format: header name is not followed by either `i`, `o`, `x`, `e`"); | |
| goto Error; | |
| } | |
| pt = quote_end + 2; | |
| @@ -232,6 +240,7 @@ h2o_logconf_t *h2o_logconf_compile(const char *fmt, int escape, char *errbuf) | |
| TYPE_MAP('l', ELEMENT_TYPE_LOGNAME); | |
| TYPE_MAP('m', ELEMENT_TYPE_METHOD); | |
| TYPE_MAP('p', ELEMENT_TYPE_LOCAL_PORT); | |
| + TYPE_MAP('e', ELEMENT_TYPE_ENV_VAR); | |
| TYPE_MAP('q', ELEMENT_TYPE_QUERY); | |
| TYPE_MAP('r', ELEMENT_TYPE_REQUEST_LINE); | |
| TYPE_MAP('s', ELEMENT_TYPE_STATUS); | |
| @@ -487,6 +496,15 @@ char *h2o_log_request(h2o_logconf_t *logconf, h2o_req_t *req, size_t *len, char | |
| RESERVE(sizeof(H2O_UINT16_LONGEST_STR) - 1); | |
| pos = append_port(pos, req->conn->callbacks->get_peername, req->conn, nullexpr); | |
| break; | |
| + case ELEMENT_TYPE_ENV_VAR: /* %{..}e */ { | |
| + //read env variable | |
| + sprintf(stdout, "getting enf" ); | |
| + h2o_iovec_t *env_var = h2o_req_getenv(req, element->data.name.base, element->data.name.len, 0); | |
| + if (env_var == NULL) | |
| + goto EmitNull; | |
| + RESERVE(env_var->len * unsafe_factor); | |
| + pos = append_unsafe_string(pos, env_var->base, env_var->len); | |
| + } break; | |
| case ELEMENT_TYPE_QUERY: /* %q */ | |
| if (req->input.query_at != SIZE_MAX) { | |
| size_t len = req->input.path.len - req->input.query_at; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment