Created
December 29, 2013 16:41
-
-
Save tclamb/8172136 to your computer and use it in GitHub Desktop.
modification of `webserver.cpp` example that shows how to use `url_obj`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <native/native.h> | |
#include <sstream> | |
using namespace native::http; | |
int main() { | |
http server; | |
int port = 8080; | |
if(!server.listen("0.0.0.0", port, [](request& req, response& res) { | |
res.set_status(200); | |
res.set_header("Content-Type", "text/plain"); | |
auto url = req.url(); | |
std::stringstream ss; | |
ss << " req.url().schema(): " << url.schema() << '\n' | |
<< " req.url().host(): " << url.host() << '\n' | |
<< " req.url().port(): " << url.port() << '\n' | |
<< " req.url().path(): " << url.path() << '\n' | |
<< " req.url().query(): " << url.query() << '\n' | |
<< "req.url().fragment(): " << url.fragment() << "\n\n" | |
<< "Note that port() == 0 and fragment() == \"\"\n"; | |
if(url.path() == "/foo") { | |
ss << "\nC++ FTW\n"; | |
} | |
res.end(ss.str()); | |
})) return 1; | |
std::cout << "Server running at http://0.0.0.0:" << port << "/" << std::endl; | |
return native::run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment