-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathHTTPSRedirect.h
86 lines (70 loc) · 2.03 KB
/
HTTPSRedirect.h
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
/* HTTPS on ESP8266 with follow redirects, chunked encoding support
* Version 2.1
* Author: Sujay Phadke
* Github: @electronicsguy
* Copyright (C) 2017 Sujay Phadke <electronicsguy123@gmail.com>
* All rights reserved.
*
*/
#pragma once
#include <WiFiClientSecure.h>
// Un-comment for extra functionality
//#define EXTRA_FNS
#define OPTIMIZE_SPEED
class HTTPSRedirect : public WiFiClientSecure {
private:
const int _httpsPort;
bool _keepAlive;
String _redirUrl;
String _redirHost;
unsigned int _maxRedirects; // to-do
const char* _contentTypeHeader;
struct headerFields{
String transferEncoding;
unsigned int contentLength;
#ifdef EXTRA_FNS
String contentType;
#endif
};
headerFields _hF;
String _Request;
struct Response{
int statusCode;
String reasonPhrase;
bool redirected;
String body;
};
Response _myResponse;
bool _printResponseBody;
void Init(void);
bool printRedir(void);
void fetchHeader(void);
bool getLocationURL(void);
void fetchBodyUnChunked(unsigned);
void fetchBodyChunked(void);
unsigned int getResponseStatus(void);
void InitResponse(void);
void createGetRequest(const String&, const char*);
void createPostRequest(const String&, const char*, const String&);
#ifdef EXTRA_FNS
void fetchBodyRaw(void);
void printHeaderFields(void);
#endif
public:
HTTPSRedirect(void);
HTTPSRedirect(const int);
~HTTPSRedirect();
bool GET(const String&, const char*);
bool GET(const String&, const char*, const bool&);
bool POST(const String&, const char*, const String&);
bool POST(const String&, const char*, const String&, const bool&);
int getStatusCode(void);
String getReasonPhrase(void);
String getResponseBody(void);
void setPrintResponseBody(bool);
void setMaxRedirects(const unsigned int);
void setContentTypeHeader(const char *);
#ifdef OPTIMIZE_SPEED
bool reConnectFinalEndpoint(void);
#endif
};