char *df_Referer; /* %{Referer}i */
char *df_Uq; /* %U%q, URL path and query string */
char *df_User_agent; /* %{User-agent}i */
+ char *df_X_Forwarded_For; /* %{X-Forwarded-For}i */
char *df_b; /* %b, Bytes */
char *df_h; /* %h (host name / IP adress)*/
char *df_m; /* %m, Request method*/
} **ll;
static size_t nll;
+static int prefer_x_forwarded_for = 0;
static int
isprefix(const char *str, const char *prefix, const char *end, const char **next)
else if (isprefix(ptr, "authorization:", end, &next) &&
isprefix(next, "basic", end, &next))
lp->df_u = trimline(next, end);
+ else if (isprefix(ptr, "x-forwarded-for:", end, &next))
+ lp->df_X_Forwarded_For = trimline(next, end);
else if (isprefix(ptr, "host:", end, &next))
lp->df_Host = trimline(next, end);
break;
else if (isprefix(ptr, "authorization:", end, &next) &&
isprefix(next, "basic", end, &next))
lp->df_u = trimline(next, end);
+ else if (isprefix(ptr, "x-forwarded-for:", end, &next))
+ lp->df_X_Forwarded_For = trimline(next, end);
else if (isprefix(ptr, "host:", end, &next))
lp->df_Host = trimline(next, end);
break;
/* %h */
if (!lp->df_h && spec & VSL_S_BACKEND)
fprintf(fo, "127.0.0.1 ");
+ else if (lp->df_X_Forwarded_For && prefer_x_forwarded_for)
+ fprintf(fo, "%s ", lp->df_X_Forwarded_For);
else
fprintf(fo, "%s ", lp->df_h ? lp->df_h : "-");
freez(lp->df_Referer);
freez(lp->df_Uq);
freez(lp->df_User_agent);
+ freez(lp->df_X_Forwarded_For);
freez(lp->df_b);
freez(lp->df_h);
freez(lp->df_m);
vd = VSL_New();
- while ((c = getopt(argc, argv, VSL_ARGS "aDn:P:Vw:")) != -1) {
+ while ((c = getopt(argc, argv, VSL_ARGS "aDn:P:Vw:f")) != -1) {
switch (c) {
case 'a':
a_flag = 1;
break;
+ case 'f':
+ prefer_x_forwarded_for = 1;
+ break;
case 'D':
D_flag = 1;
break;