/
IsapiRequest.h
120 lines (82 loc) · 3.13 KB
/
IsapiRequest.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "WebRequest.h"
#include <sstream>
#include <httpext.h>
namespace Wt {
namespace isapi {
class IsapiServer;
class IsapiRequest : public WebRequest
{
public:
IsapiRequest(LPEXTENSION_CONTROL_BLOCK ecb, IsapiServer *server,
bool forceSynchronous);
~IsapiRequest();
// Signal ISAPI that this connection is to be closed and that we're
// done with it. The IsapiRequest object must be deleted after calling
// this method.
void abort();
// Returns true if the HTTP request was received without errors
bool isGood();
virtual bool isSynchronous() const;
virtual void flush(ResponseState state = ResponseDone,
const WriteCallback& callback = WriteCallback());
// Sends a simple text reply
void sendSimpleReply(int status, const std::string &msg);
virtual std::istream& in() { return *in_; }
virtual std::ostream& out() { return out_; }
virtual std::ostream& err() { return err_; }
virtual void setStatus(int status);
virtual void setContentLength(boost::intmax_t length);
virtual void setContentType(const std::string& value);
virtual void addHeader(const std::string& name, const std::string& value);
virtual void setRedirect(const std::string& url);
virtual const char *headerValue(const char *name) const;
virtual std::vector<Wt::Http::Message::Header> headers() const;
virtual const char *envValue(const char *name) const;
virtual const std::string &scriptName() const;
virtual const std::string &serverName() const;
virtual const char *requestMethod() const;
virtual const std::string &queryString() const;
virtual const std::string &serverPort() const;
virtual const std::string &pathInfo() const;
virtual const std::string &remoteAddr() const;
virtual const char *urlScheme() const;
virtual WSslInfo *sslInfo() const;
private:
LPEXTENSION_CONTROL_BLOCK ecb_;
IsapiServer *server_;
bool good_;
bool synchronous_;
bool reading_;
DWORD bytesToRead_;
char buffer_[1024];
DWORD bufferSize_;
//boost::mutex intermediateBufferedLock_;
//int intermediateBufferedCounter_;
void processAsyncRead(DWORD cbIO, DWORD dwError, bool first);
static void WINAPI completionCallback(LPEXTENSION_CONTROL_BLOCK lpECB,
PVOID pContext, DWORD cbIO, DWORD dwError);
void writeSync();
void writeAsync(DWORD cbIO, DWORD dwError, bool first);
void flushDone();
std::vector<std::string> writeData_;
unsigned int writeIndex_; // next index to be written in writeData_
unsigned int writeOffset_; // offset withing current item of writeData_
ResponseState flushState_;
std::stringstream header_, in_mem_, out_, err_;
std::iostream *in_;
std::string requestFileName_;
bool chunking_;
boost::intmax_t contentLength_;
bool headerSent_;
void sendHeader();
enum {HTTP_1_0, HTTP_1_1} version_;
// Returns a reference to a string that's safe to use until this object is
// deleted (we used to return by value but the built-in httpd optimizations
// required a different approach)
std::string *persistentEnvValue(const char *name) const;
// storage used by persistentEnvValue
mutable std::vector<std::string *> strings_;
std::string emptyString_;
};
}
}