evpp响应的内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | #pragma once #include "evpp/inner_pre.h" #include "evpp/slice.h" #include "evpp/timestamp.h" #include <map> struct evhttp_request; namespace evpp { class EventLoop; } namespace evpp { namespace http { class Service; struct EVPP_EXPORT Context { public : Context( struct evhttp_request* r); ~Context(); bool Init(); void AddResponseHeader( const std::string& key, const std::string& value); // Finds the value belonging to a header. // // @param key the name of the header to find // @returns a pointer to the value for the header or nullptr if the header // could not be found. const char * FindRequestHeader( const char * key); // The original URI, with original parameters, e.g. : /status.html?code=utf8 const char * original_uri() const ; // The URI without any parameters const std::string& uri() const { return uri_; } const std::string& remote_ip() const { return remote_ip_; } const Slice& body() const { return body_; } struct evhttp_request* req() const { return req_; } void set_response_http_code( int code) { response_http_code_ = code; } int response_http_code() const { return response_http_code_; } // Get the first value associated with the given key from the URI. std::string GetQuery( const char * query_key, size_t key_len) { const char * u = original_uri(); return FindQueryFromURI(u, strlen (u), query_key, key_len); } std::string GetQuery( const std::string& query_key) { return GetQuery(query_key.data(), query_key.size()); } public : static std::string FindClientIPFromURI( const char * uri, size_t uri_len) { static const std::string __s_clientip = "clientip" ; return FindQueryFromURI(uri, uri_len, __s_clientip.data(), __s_clientip.size()); } // @brief Get the first value associated with the given key from the URI. // If there are no values associated with the key, returns an empty string. // @param[IN] uri - The uri with parameters // @param[IN] uri_len - The uri length // @param[IN] key - // @param[IN] key_len - // @return std::string - static std::string FindQueryFromURI( const char * uri, size_t uri_len, const char * key, size_t key_len); static std::string FindQueryFromURI( const char * uri, const char * key); static std::string FindQueryFromURI( const std::string& uri, const std::string& key); private : // The URI without any parameters : e.g. /status.html std::string uri_; // The remote client IP. // If the HTTP request is forwarded by Nginx, // we will prefer to use the value of 'clientip' parameter in URL // @see The reverse proxy Nginx configuration : proxy_pass http://127.0.0.1:8080/get/?clientip=$remote_addr; std::string remote_ip_; int response_http_code_ = 200; // The HTTP request body data Slice body_; struct evhttp_request* req_; }; typedef std::shared_ptr<Context> ContextPtr; typedef std::function< void ( const std::string& response_data)> HTTPSendResponseCallback; typedef std::function < void (EventLoop* loop, const ContextPtr& ctx, const HTTPSendResponseCallback& respcb) > HTTPRequestCallback; typedef std::map<std::string /*The uri*/ , HTTPRequestCallback> HTTPRequestCallbackMap; } } |
分类:
c++语言
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2022-07-31 前端
2020-07-31 非阻塞socket
2020-07-31 vscode 中文
2020-07-31 curses
2020-07-31 Trie
2020-07-31 c tcp server
2020-07-31 linux高性能服务器编程(tcp超时)