forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApacheServerResponse.cpp
More file actions
executable file
·131 lines (93 loc) · 2.54 KB
/
ApacheServerResponse.cpp
File metadata and controls
executable file
·131 lines (93 loc) · 2.54 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
//
// ApacheServerResponse.cpp
//
// $Id: //poco/1.4/ApacheConnector/src/ApacheServerResponse.cpp#3 $
//
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "ApacheServerResponse.h"
#include "ApacheServerRequest.h"
#include "ApacheStream.h"
#include "ApacheConnector.h"
#include "Poco/Net/HTTPCookie.h"
#include "Poco/File.h"
#include "Poco/Exception.h"
#include <fstream>
#include <vector>
using Poco::File;
using Poco::OpenFileException;
using Poco::Net::HTTPCookie;
ApacheServerResponse::ApacheServerResponse(ApacheServerRequest* pRequest):
_pStream(0),
_pApacheRequest(pRequest->_pApacheRequest)
{
setVersion(pRequest->getVersion());
setKeepAlive(pRequest->getKeepAlive());
pRequest->setResponse(this);
}
ApacheServerResponse::~ApacheServerResponse()
{
delete _pStream;
}
void ApacheServerResponse::initApacheOutputStream()
{
poco_assert (!_pStream);
_pApacheRequest->setContentType(getContentType());
std::vector<HTTPCookie> cookies;
getCookies(cookies);
std::size_t cnt = cookies.size();
for (int c = 0; c < cnt; c++)
{
_pApacheRequest->addHeader("Set-Cookie", cookies[c].toString());
}
_pStream = new ApacheOutputStream(_pApacheRequest);
}
void ApacheServerResponse::sendContinue()
{
// should be handled by Apache
}
std::ostream& ApacheServerResponse::send()
{
poco_assert (!_pStream);
initApacheOutputStream();
return *_pStream;
}
void ApacheServerResponse::sendFile(const std::string& path, const std::string& mediaType)
{
poco_assert (!_pStream);
initApacheOutputStream();
File f(path);
if (_pApacheRequest->sendFile(path, static_cast<unsigned int>(f.getSize()), mediaType) != 0)
throw OpenFileException(path);
}
void ApacheServerResponse::sendBuffer(const void* pBuffer, std::size_t length)
{
poco_assert (!_pStream);
initApacheOutputStream();
_pStream->write(static_cast<const char*>(pBuffer), static_cast<std::streamsize>(length));
}
void ApacheServerResponse::redirect(const std::string& uri, HTTPStatus status)
{
poco_assert (!_pStream);
initApacheOutputStream();
try
{
_pApacheRequest->redirect(uri, status);
}
catch (Poco::Exception&)
{
ApacheConnector::log(__FILE__, __LINE__, 7 , 0, "caught exception in ApacheServerResponse::redirect - ignoring\n");
}
}
void ApacheServerResponse::sendErrorResponse(int status)
{
initApacheOutputStream();
_pApacheRequest->sendErrorResponse(status);
}
void ApacheServerResponse::requireAuthentication(const std::string& realm)
{
// should be handled by Apache
}