part 2 of 2<p><pre><code> # make new http client (yy025)
# hh2 is an #include in 025.l below
yy018 < hh1 > hh2;
flex -8iCrfa 025.l;
# cpp -P 025.l|less;
cc -static -o yy025 lex.yy.c;
</code></pre>
save as "025.l"<p><pre><code> #define httpMethod "GET"
#define httpVersion "1.1"
#define Host ""
#define jmp BEGIN
#define se setenv
#define g getenv
#define p(x,y) fprintf(stdout,x,y)
int count,path,ka;
int httpheaders()
{
se("httpMethod",httpMethod,0);p("%s ",g("httpMethod"));
p("%s HTTP/",g("Path"));
se("httpVersion",httpVersion,0);p("%s\r\n",g("httpVersion"));
#include "hh2"
fputs("\r\n",stdout);
}
int keepaliveclose()
{
se("Connection","close",1);
}
%s xa xb xc
xa "http://"|"https://"
xb [-A-Za-z0-9.:]*
xc [^#'|<> \r\n]*
%%
^{xa} count++;se("Scheme",yytext,0);jmp xa;
<xa>{xb} se("Host",yytext,1);if(!g("Host"))se("Host",Host,0);jmp xb;
<xb>\n path=0;se("Path","/",0);httpheaders();jmp 0;
<xb>{xc} path=1;se("Path",yytext,1);httpheaders();jmp 0;
.|\n
%%
int main()
{
yylex();
if(!g("nokac"))if(count>1){keepaliveclose();httpheaders();}
}
int yywrap()
{
/* dprintf(6,"%s",g("Host")); */
}</code></pre>