X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tests%2Flib%2FWebServer.h;h=47700a59427fff24bdc40e4ea0cb24afb1f52816;hb=3b182924676f72368fceb712b6bd8af3fd479f81;hp=be0f8e87b3b23ea45634f2787fcc3717cab21f1a;hpb=d58a5d90878551ca9fde5de55c8a026453ac32ca;p=platform%2Fupstream%2Flibzypp.git diff --git a/tests/lib/WebServer.h b/tests/lib/WebServer.h index be0f8e8..47700a5 100644 --- a/tests/lib/WebServer.h +++ b/tests/lib/WebServer.h @@ -5,6 +5,9 @@ #include "zypp/Url.h" #include "zypp/Pathname.h" #include "zypp/base/PtrTypes.h" +#include "zypp/media/TransferSettings.h" + +#include /** * @@ -33,15 +36,31 @@ class WebServer { public: + + struct Request { + Request ( std::istream::__streambuf_type *rinbuf, + std::ostream::__streambuf_type *routbuf, + std::ostream::__streambuf_type *rerrbuf ); + std::string path; + std::map< std::string, std::string > params; + std::istream rin; + std::ostream rout; + std::ostream rerr; + }; + + using RequestHandler = std::function; + /** * creates a web server on \ref root and \port */ - WebServer(const zypp::Pathname &root, unsigned int port=10001); + WebServer(const zypp::Pathname &root, unsigned int port=10001, bool useSSL = false ); ~WebServer(); /** * Starts the webserver worker thread + * Waits up to 10 seconds and returns whether the port is now active. */ - void start(); + bool start(); + /** * Stops the worker thread */ @@ -58,14 +77,60 @@ class WebServer zypp::Url url() const; /** + * generates required transfer settings + */ + zypp::media::TransferSettings transferSettings () const; + + /** * shows the log of last run */ std::string log() const; + /** + * Checks if the server was stopped + */ + bool isStopped() const; + + /** + * Sets the request handler callback, if a callback for the path does already exist + * it is replaced, can be called at any time + * + * \note a request handler path is always prefixed with /handler so to call a handler named test, the + * URL is "http://localhost/handler/test" + */ + void addRequestHandler ( const std::string &path, RequestHandler &&handler ); + + /*! + * Removes a registered request hander, can be called at any time + */ + void removeRequestHandler ( const std::string &path ); + + /*! + * Creates a request handler that simply returns the string in \a resp + */ + static RequestHandler makeResponse(std::string resp); + + /*! + * Creates a request handler that sends a HTTP response with \a status and \a content + * in the respose + */ + static RequestHandler makeResponse(std::string status, std::string content); + + /*! + * Creates a request handler that sends a HTTP response with \a status \a content + * and \a headers in the respose + */ + static RequestHandler makeResponse(const std::string &status, const std::vector &headers, const std::string &content); + + /*! + * Creates the corresponding HTTP response to the given parameters + */ + static std::string makeResponseString ( const std::string &status, const std::vector &headers, const std::string &content ); + class Impl; private: /** Pointer to implementation */ - zypp::RWCOW_pointer _pimpl; + zypp::RW_pointer _pimpl; }; #endif