http.get is now operational
This commit is contained in:
@@ -19,10 +19,11 @@
|
||||
#include "wrap-map.hpp"
|
||||
#include "luastack.hpp"
|
||||
#include "streambuffer.hpp"
|
||||
#include "drivenengine.hpp"
|
||||
|
||||
using UrlParameters = eng::map<eng::string, eng::string>;
|
||||
|
||||
class HttpOutRequest : public eng::nevernew {
|
||||
class HttpClientRequest : public eng::nevernew {
|
||||
private:
|
||||
// Request IDs.
|
||||
int64_t request_id_;
|
||||
@@ -59,14 +60,10 @@ private:
|
||||
public:
|
||||
// Construct an empty HTTP request.
|
||||
// All of the fields have empty values.
|
||||
HttpOutRequest();
|
||||
HttpClientRequest();
|
||||
|
||||
// Get the request IDs.
|
||||
int64_t request_id() const { return request_id_; }
|
||||
int64_t place_id() const { return place_id_; }
|
||||
int64_t thread_id() const { return thread_id_; }
|
||||
|
||||
// Get request-related fields.
|
||||
//
|
||||
const eng::string &error() const { return error_; }
|
||||
bool verify_certificate() const { return verify_certificate_; }
|
||||
const eng::string &method() const { return method_; }
|
||||
@@ -74,20 +71,13 @@ public:
|
||||
int port() const { return port_; }
|
||||
const eng::string &path() const { return path_; }
|
||||
|
||||
// Get the network target, eg, "cert:host:port"
|
||||
eng::string target() const;
|
||||
|
||||
// Set the request IDs.
|
||||
void set_request_id(int64_t request_id) { request_id_ = request_id; }
|
||||
void set_place_id(int64_t place_id) { place_id_ = place_id; }
|
||||
void set_thread_id(int64_t thread_id) { thread_id_ = thread_id; }
|
||||
|
||||
// Populate an HTTP request a piece at a time.
|
||||
// Populate an request-related fields one piece at a time.
|
||||
// If you pass an invalid value, or if the field is
|
||||
// already set, the routine will generate an error message
|
||||
// and store it in the error field. In that case, the set
|
||||
// will not happen. If there's already an error in the error
|
||||
// field, it will not be overwritten.
|
||||
//
|
||||
void set_verify_certificate(bool flag);
|
||||
void set_method(const eng::string &method);
|
||||
void set_host(const eng::string &host);
|
||||
@@ -96,7 +86,6 @@ public:
|
||||
void set_param(const eng::string &key, const eng::string &value);
|
||||
void set_url(std::string_view url);
|
||||
|
||||
// Same as above, but using Lua values.
|
||||
void set_verify_certificate(LuaStack &LS, LuaSlot val);
|
||||
void set_method(LuaStack &LS, LuaSlot val);
|
||||
void set_host(LuaStack &LS, LuaSlot val);
|
||||
@@ -106,18 +95,29 @@ public:
|
||||
void set_params(LuaStack &LS, LuaSlot tab);
|
||||
void set_url(LuaStack &LS, LuaSlot val);
|
||||
|
||||
// Set default values for any fields that should have
|
||||
// defaults. This must be done after setting regular
|
||||
// values.
|
||||
// Set default values for method and port.
|
||||
// This must be done after setting regular values.
|
||||
void set_defaults();
|
||||
|
||||
// Populate request-related fields from a Lua table.
|
||||
void set_config(LuaStack &LS0, LuaSlot tab);
|
||||
|
||||
// Get or Set the request IDs.
|
||||
// This class does just stores these.
|
||||
int64_t request_id() const { return request_id_; }
|
||||
int64_t place_id() const { return place_id_; }
|
||||
int64_t thread_id() const { return thread_id_; }
|
||||
void set_request_id(int64_t request_id) { request_id_ = request_id; }
|
||||
void set_place_id(int64_t place_id) { place_id_ = place_id; }
|
||||
void set_thread_id(int64_t thread_id) { thread_id_ = thread_id; }
|
||||
|
||||
// Get the network target, eg, "cert:host:port"
|
||||
eng::string target() const;
|
||||
|
||||
// Verify that the request is error free and that
|
||||
// defaults have been set.
|
||||
eng::string check() const;
|
||||
|
||||
// Populate an HTTP request from a Lua table.
|
||||
void set_config(LuaStack &LS0, LuaSlot tab);
|
||||
|
||||
// Put the request into the stream, assuming HTTP/1.1
|
||||
void send(StreamBuffer *target) const { send_internal(target, false); }
|
||||
|
||||
@@ -129,14 +129,11 @@ public:
|
||||
eng::string DebugString();
|
||||
};
|
||||
|
||||
class HttpOutRequestMap : public eng::map<int64_t, HttpOutRequest> {
|
||||
public:
|
||||
void serialize(StreamBuffer *sb) const;
|
||||
void deserialize(StreamBuffer *sb);
|
||||
};
|
||||
|
||||
class HttpInResponse {
|
||||
class HttpClientResponse {
|
||||
private:
|
||||
// The request ID.
|
||||
int64_t request_id_;
|
||||
|
||||
// The HTTP response status code.
|
||||
int status_code_;
|
||||
|
||||
@@ -198,7 +195,7 @@ public:
|
||||
const int64_t MAX_CONTENT_LENGTH = 1000000;
|
||||
|
||||
// Construct a blank response.
|
||||
HttpInResponse();
|
||||
HttpClientResponse();
|
||||
|
||||
// Store a result code and an error message, and clear the content.
|
||||
// This is generally used when the client detects an error,
|
||||
@@ -209,7 +206,7 @@ public:
|
||||
// Parse the HTTP response. The closed flag is to be set to true if the
|
||||
// remote has closed the connection.
|
||||
//
|
||||
// If the request is incomplete, generates a 600 incomplete error. In that
|
||||
// If the request is incomplete, generates a status code of zero. In that
|
||||
// case, loading more data from the server might improve the situation.
|
||||
//
|
||||
// Note that the response is not ever removed from the StreamBuffer, which
|
||||
@@ -218,6 +215,14 @@ public:
|
||||
//
|
||||
void parse(const StreamBuffer *sb, bool closed);
|
||||
|
||||
// Return true if the response is complete.
|
||||
bool complete() const { return status_code_ != 0; }
|
||||
|
||||
// Get or Set the request ID.
|
||||
// This class does nothing with the request ID, it just stores it.
|
||||
int64_t request_id() const { return request_id_; }
|
||||
void set_request_id(int64_t v) { request_id_ = v; }
|
||||
|
||||
// Convert the HTTP response to a lua table.
|
||||
void store(LuaStack &LS, LuaSlot tab) const;
|
||||
|
||||
@@ -228,4 +233,25 @@ public:
|
||||
static void store_fail(LuaStack &LS, LuaSlot tab, int status_code, std::string_view error);
|
||||
};
|
||||
|
||||
class HttpClientRequestMap : public eng::map<int64_t, HttpClientRequest> {
|
||||
public:
|
||||
void serialize(StreamBuffer *sb) const;
|
||||
void deserialize(StreamBuffer *sb);
|
||||
};
|
||||
|
||||
using HttpClientResponseVec = eng::vector<HttpClientResponse>;
|
||||
|
||||
// This class associates an HTTP request to an actual communication
|
||||
// channel that is executing that request.
|
||||
|
||||
class HttpClientChannel {
|
||||
public:
|
||||
SharedChannel channel_;
|
||||
int64_t parsed_bytes_;
|
||||
|
||||
HttpClientChannel() : parsed_bytes_(0) {}
|
||||
};
|
||||
|
||||
using HttpClientChannelMap = eng::map<int64_t, HttpClientChannel>;
|
||||
|
||||
#endif // HTTP_HPP
|
||||
|
||||
Reference in New Issue
Block a user