7 #include <lib/base/object.h>
8 #include <lib/base/eptrlist.h>
9 #include <lib/base/ebase.h>
11 #include <lib/base/eerror.h>
12 #include <lib/network/socket.h>
13 #include <lib/network/serversocket.h>
15 class eHTTPConnection;
16 class eHTTPDataSource;
19 class eHTTPDataSource;
20 typedef ePtr<eHTTPDataSource> eHTTPDataSourcePtr;
22 class iHTTPPathResolver: public iObject
25 virtual ~iHTTPPathResolver() {};
26 virtual RESULT getDataSource(eHTTPDataSourcePtr &source, std::string request, std::string path, eHTTPConnection *conn)=0;
29 class eHTTPDataSource: public iObject
32 eHTTPConnection *connection;
34 eHTTPDataSource(eHTTPConnection *c);
35 virtual ~eHTTPDataSource();
36 virtual void haveData(void *data, int len);
37 virtual int doWrite(int bytes); // number of written bytes, -1 for "no more"
40 typedef ePtr<eHTTPDataSource> eHTTPDataSourcePtr;
42 class eHTTPError: public eHTTPDataSource
44 DECLARE_REF(eHTTPError);
48 eHTTPError(eHTTPConnection *c, int errcode);
51 int doWrite(int bytes);
54 class eHTTPConnection: public eSocket
56 void doError(int error);
58 int getLine(std::string &line);
60 int processLocalState();
61 int processRemoteState();
62 void writeString(const char *data);
64 eHTTPDataSourcePtr data;
71 void bytesWritten(int);
75 Signal1<void,int> transferDone;
76 Signal1<eHTTPDataSource*,eHTTPConnection*> createDataSource;
82 < If-modified-since: bla
86 > Content-Type: text/html
91 stateWait, stateRequest, stateResponse, stateHeader, stateData, stateDone, stateClose
93 int localstate, remotestate;
96 eHTTPConnection(int socket, int issocket, eHTTPD *parent, int persistent=0);
97 eHTTPConnection(eMainloop *ml); // ready to do "connectToHost"
98 static eHTTPConnection *doRequest(const char *uri, eMainloop *ml, int *error=0);
104 std::string request, requestpath, httpversion;
110 std::string code_descr;
112 std::map<std::string,std::string> remote_header, local_header;
115 int content_length, content_length_remaining;
118 class eHTTPD: public eServerSocket
120 friend class eHTTPConnection;
121 eSmartPtrList<iHTTPPathResolver> resolver;
124 eHTTPD(int port, eMainloop *ml);
125 void newConnection(int socket);
127 void addResolver(iHTTPPathResolver *r) { resolver.push_back(r); }
128 void removeResolver(iHTTPPathResolver *r) { resolver.remove(r); }