1 #include <HttpdSocket.h>
2 #include <SocketHandler.h>
3 #include <ListenSocket.h>
5 #include <HttpPostSocket.h>
6 #include <HttpPutSocket.h>
10 class sSocket
: public HttpdSocket
13 sSocket(ISocketHandler
& h
) : HttpdSocket(h
) {
18 if (GetParent() -> GetPort() == 443 || GetParent() -> GetPort() == 8443)
23 fprintf(stderr
, "SSL not available\n");
32 GetForm() -> getfirst(name
, value
);
35 fprintf(stderr
, "%s: '%s'\n", name
.c_str(), value
.c_str());
36 GetForm() -> getnext(name
, value
);
46 fprintf(stderr
, "Uri: '%s'\n", GetUri().c_str());
49 for (size_t i
= 0; i
< GetUri().size(); i
++)
50 if (GetUri()[i
] == '.')
52 std::string ext
= GetUri().substr(x
+ 1);
53 if (ext
== "gif" || ext
== "jpg" || ext
== "png")
54 AddResponseHeader("Content-type", "image/" + ext
);
56 AddResponseHeader("Content-type", "text/" + ext
);
58 AddResponseHeader("Connection", "close");
62 void GenerateDocument()
64 Send("<html></html>");
71 InitializeContext("httpd", "comb.pem", "", SSLv23_method());
78 int main(int argc
, char *argv
[])
80 std::string host
= argc
> 1 ? argv
[1] : "www.alhem.net";
82 SocketHandler
h(&log
);
83 ListenSocket
<sSocket
> l(h
);
86 printf("Bind port 1028 failed\n");
90 ListenSocket
<sSocket
> l2(h
);
93 printf("Bind port 8443 failed\n");
97 HttpPostSocket
sock(h
, "http://localhost:1028/postdata");
98 sock
.AddField("name", "value");