Giter VIP home page Giter VIP logo

asio_http's Introduction

asio_http

About


ASIO_HTTP is a free, cross-platform HTTP server framework that uses Boost::asio to handle network services. Its API is similar to the Python Django framework.

使用的cpp库


boost::asio boost::json

Simple


1、在webapp/urls.cpp中添加,"/uploda"是路由,savefile是views.cpp中的函数。

std::map<std::string, std::function<void (request&)>> urlpatterns = {
        {"/upload", savefile},
};

2、views.cpp中的函数例子

void savefile(h_context &c) {
        utils::print_req(c.request_);
        std::string filename;



        for(auto it:c.request_.body_vhs){
            if(std::string::npos!=it.find("filename=")){
                filename = extract_filename(it);
            }
        }

        save_file(c.request_.content, filename);

        json::object response_json;
        response_json["h"] = "Ture";
        std::string json_str = json::serialize(response_json);


        c.reply_.josnstr(json_str);


}

request结构为

        struct request
        {
//            request();
            std::string method;
            std::string uri;
            int http_version_major;
            int http_version_minor;
            std::vector<header> headers;
            std::string body;
            int content_length;
            std::string boundary;
            std::string content;
            std::vector<header> body_headers;
            std::vector<std::string> body_vhs;

            std::string body_hstr;
            


            std::string get_boundary() ;
            std::string extract_content();
            

        };

3、run "Usage: http_server

<doc_root>

cd cmake-build-debug 
make 

./asio_http 0.0.0.0 8090 doc_root

asio_http's People

Contributors

kadbbs avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.