📄 httpcli.h
字号:
#ifndef __HTTPCLI_H#define __HTTPCLI_H#include "Url.h"#include "Socket.h"#include "Task.h"/* Some status code validation macros: */#define H_20X(x) (((x) >= 200) && ((x) < 300))#define H_PARTIAL(x) ((x) == HTTP_PARTIAL_CONTENTS)#define H_REDIRECTED(x) (((x) == HTTP_MOVED_PERMANENTLY) || ((x) == HTTP_MOVED_TEMPORARILY))/* HTTP/1.0 status codes from RFC1945, given for reference. *//* Successful 2xx. */#define HTTP_OK 200#define HTTP_CREATED 201#define HTTP_ACCEPTED 202#define HTTP_NO_CONTENT 204#define HTTP_PARTIAL_CONTENTS 206/* Redirection 3xx. */#define HTTP_MULTIPLE_CHOICES 300#define HTTP_MOVED_PERMANENTLY 301#define HTTP_MOVED_TEMPORARILY 302#define HTTP_NOT_MODIFIED 304/* Client error 4xx. */#define HTTP_BAD_REQUEST 400#define HTTP_UNAUTHORIZED 401#define HTTP_FORBIDDEN 403#define HTTP_NOT_FOUND 404/* Server errors 5xx. */#define HTTP_INTERNAL 500#define HTTP_NOT_IMPLEMENTED 501#define HTTP_BAD_GATEWAY 502#define HTTP_UNAVAILABLE 503#define DYNAMIC_LINE_BUFFER 40typedef struct { long Len; // Received length. long ContentLen; //Expected length. long RestVal; // The restart value. int Result; // The result of last read. /* * added by grendel * * -1 = accept ranges not found * * 0 = accepts range is none * * 1 = accepts ranges */ int AcceptRanges; char * NewLoc; // New location (redirection). char * RemoteTime; //Remote time-stamp string. char * Error; // Textual HTTP error. int StatusCode; // Status code. long dlTime; //Time of the download. } HttpStat;class THttpCli {private : TUrl * up; int StatusCode; char * hdr; TSocketCli * Sckp; public : THttpCli(TUrl * u); ~THttpCli(void); uerr_t Connect(void); uerr_t Disconnect(void); int BufReadChar(int fd, char * ret); int BufPeek(int fd, char * ret); uerr_t FetchNextHeader(int fd, char **hdr); int ParseStatLine(const char *hdr, const char **rp); int SkipLws(const char *hdr); long GetLen(const char *hdr); long GetRange(const char *hdr); char * GetLocation(const char *hdr); char * GetModified(const char *hdr); int GetAcceptRanges(const char *hdr); uerr_t GetHttpInfo(TUrl * up, HttpStat * hs); uerr_t FetchHeaders(int Sock, TUrl * up, HttpStat * hs, char * Cmd); uerr_t RetrFileKnownSize(TThread * This); uerr_t RetrFileUnknownSize(TThread * This); uerr_t GetFileChunk(TThread * This); uerr_t GetCompleteFile(TThread * This);// uerr_t SearchMirrorSite(TThread * This); uerr_t RedirectionParse(TUrl * up, HttpStat * hsp);};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -