7 #include <lib/base/eptrlist.h>
8 #include <lib/base/ebase.h>
10 #include <lib/base/eerror.h>
11 #include <lib/network/socket.h>
12 #include <lib/network/serversocket.h>
14 class eHTTPConnection;
15 class eHTTPDataSource;
18 class eHTTPPathResolver
21 virtual ~eHTTPPathResolver() {};
22 virtual eHTTPDataSource *getDataSource(std::string request, std::string path, eHTTPConnection *conn)=0;
28 eHTTPConnection *connection;
30 eHTTPDataSource(eHTTPConnection *c);
31 virtual ~eHTTPDataSource();
32 virtual void haveData(void *data, int len);
33 virtual int doWrite(int bytes); // number of written bytes, -1 for "no more"
36 class eHTTPError: public eHTTPDataSource
40 eHTTPError(eHTTPConnection *c, int errcode);
43 int doWrite(int bytes);
46 class eHTTPConnection: public eSocket
48 void doError(int error);
50 int getLine(std::string &line);
52 int processLocalState();
53 int processRemoteState();
54 void writeString(const char *data);
56 eHTTPDataSource *data;
63 void bytesWritten(int);
67 Signal1<void,int> transferDone;
68 Signal1<eHTTPDataSource*,eHTTPConnection*> createDataSource;
74 < If-modified-since: bla
78 > Content-Type: text/html
83 stateWait, stateRequest, stateResponse, stateHeader, stateData, stateDone, stateClose
85 int localstate, remotestate;
88 eHTTPConnection(int socket, int issocket, eHTTPD *parent, int persistent=0);
89 eHTTPConnection(eMainloop *ml); // ready to do "connectToHost"
90 static eHTTPConnection *doRequest(const char *uri, eMainloop *ml, int *error=0);
96 std::string request, requestpath, httpversion;
102 std::string code_descr;
104 std::map<std::string,std::string> remote_header, local_header;
107 int content_length, content_length_remaining;
110 class eHTTPD: public eServerSocket
112 friend class eHTTPConnection;
113 ePtrList<eHTTPPathResolver> resolver;
116 eHTTPD(int port, eMainloop *ml);
117 void newConnection(int socket);
119 void addResolver(eHTTPPathResolver *r) { resolver.push_back(r); }
120 void removeResolver(eHTTPPathResolver *r) { resolver.remove(r); }