#pragma once


enum HttpRequestType
{
	HttpGet = 0,
	HttpPost,
};
//枚举下载状态
enum DownloadState
{
	HttpLoading = 0,
	HttpFialed,
	HttpFinished,
};

/******************************************************
*定义错误信息
*
******************************************************/
enum HttpInterfaceError
{
	HttpErrorSuccess = 0,		//成功
	HttpErrorInit,				//初始化失败
	HttpErrorConnect,			//连接HTTP服务器失败
	HttpErrorSend,				//发送请求失败
	HttpErrorQuery,				//查询HTTP请求头失败
	HttpError404,				//页面不存在
	HttpErrorIllegalUrl,		//无效的URL
	HttpErrorCreateFile,		//创建文件失败
	HttpErrorDownload,			//下载失败
	HttpErrorQueryIP,			//获取域名对应的地址失败
	HttpErrorSocket,			//套接字错误
	HttpErrorUserCancel,		//用户取消下载
	HttpErrorBuffer,			//文件太大，缓冲区不足
	HttpErrorHeader,			//HTTP请求头错误
	HttpErrorParam,				//参数错误，空指针，空字符……
	HttpErrorWriteFile,			//写入文件失败
	HttpErrorUnknow,			//未知错误

};
//下载的回调
class IHttpCallback
{
public:
	virtual void	OnDownloadCallback(void* pParam, DownloadState state, double nTotalSize, double nLoadSize) = 0;
	virtual bool	IsNeedStop() = 0;
};
//定义每次读取数据的缓冲区大小 4KB
#define READ_BUFFER_SIZE		4096

//内存中设置的缓冲区大小 8M
#define DOWNLOAD_BUFFER_SIZE	(8*1024*1024)

//回调参数信息
struct HttpParamsData
{
	void* lpparam;//自定义数据
	IHttpCallback* callback;//回调函数
	HttpInterfaceError errcode;//错误码
};


//定义常用http头名称
#define HEADER_USER_AGENT			"User-Agent"
#define HEADER_CONNECTION			"Connection"
#define HEADER_ACCEPT				"Accept"
#define HEADER_ACCEPT_ENCODING		"Accept-Encoding"
#define HEADER_ACCEPT_LANGUAGE		"Accept-Language"
#define HEADER_CONTENT_TYPE			"Content-Type"
#define HEADER_HOST					"Host"
#define HEADER_RANGE				"Range"
#define HEADER_LOCATION				"Location"
#define HEADER_CONTENT_LENGTH		"Content-Length"


//默认HTTP版本
static const char default_http_version[] = "HTTP/1.1";

//定义默认的userAgent
static const char default_user_agent[] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.4044.92 Safari/537.36";

//默认接收类型
static const char default_accept[] = "*/*";

//默认保持连接
static const char default_connection[] = "Keep-Alive";

//默认语言
static const char default_language[] = "zh-CN,zh;q=0.9";

//HTTP协议换行符
static const char http_newline[] = "\r\n";
