view include/core/http.h @ 261:3ec7804abf17

include: make header guards more sane The C++ standard[1] says: Each identifier that contains a double underscore __ or begins with an underscore followed by an uppercase letter is reserved to the implementation for any use. [1]: https://timsong-cpp.github.io/cppwp/n4659/lex.name#3.1
author Paper <paper@paper.us.eu.org>
date Wed, 03 Apr 2024 20:04:28 -0400
parents 862d0d8619f6
children 9a88e1725fd2
line wrap: on
line source

#ifndef MINORI_CORE_HTTP_H_
#define MINORI_CORE_HTTP_H_

#include <QByteArray>
#include <QThread>
#include <string>
#include <vector>

namespace HTTP {

QByteArray Get(const std::string& url, const std::vector<std::string>& headers = {});
QByteArray Post(const std::string& url, const std::string& data, const std::vector<std::string>& headers = {});

class GetThread : public QThread {
	Q_OBJECT

public:
	GetThread(const std::string& u, const std::vector<std::string>& h = {}, QObject* parent = nullptr)
	    : QThread(parent) {
		url = u;
		headers = h;
	}

signals:
	void ReceivedData(const QByteArray& ba);

protected:
	void run() override { emit ReceivedData(Get(url, headers)); }

	std::string url;
	std::vector<std::string> headers;
};

class PostThread : public QThread {
	Q_OBJECT

public:
	PostThread(const std::string& u, const std::string& d, const std::vector<std::string>& h = {},
	           QObject* parent = nullptr)
	    : QThread(parent) {
		url = u;
		data = d;
		headers = h;
	}

signals:
	void ReceivedData(const QByteArray& ba);

protected:
	void run() override { emit ReceivedData(Post(url, data, headers)); }

	std::string url;
	std::string data;
	std::vector<std::string> headers;
};

} // namespace HTTP

#endif // MINORI_CORE_HTTP_H_