various improvements - see CHANGELOG

This commit is contained in:
Guenter Obiltschnig
2012-07-26 16:51:12 +00:00
parent c5efc7c971
commit 60ca63c02b
26 changed files with 196 additions and 83 deletions

View File

@@ -1,6 +1,6 @@
This is the changelog file for the POCO C++ Libraries. This is the changelog file for the POCO C++ Libraries.
Release 1.4.4 (2012-05-??) Release 1.4.4 (2012-08-??)
========================== ==========================
- ZipStream now builds correctly in unbundled build. - ZipStream now builds correctly in unbundled build.
@@ -30,6 +30,10 @@ Release 1.4.4 (2012-05-??)
- Added Poco::ObjectPool class template. - Added Poco::ObjectPool class template.
- Poco::Net::HTTPServer has a new stopAll() method allowing stopping/aborting of all - Poco::Net::HTTPServer has a new stopAll() method allowing stopping/aborting of all
currently active client connections. currently active client connections.
- The HTTP server framework now actively prevents sending a message body in the
response to a HEAD request, or in case of a 204 No Content or 304 Not Modified
response status.
- fixed a DOM parser performance bug (patch by Peter Klotz)
Release 1.4.3p1 (2012-01-23) Release 1.4.3p1 (2012-01-23)
@@ -1710,4 +1714,4 @@ building the libraries.
-- --
$Id: //poco/1.4/dist/CHANGELOG#60 $ $Id: //poco/1.4/dist/CHANGELOG#62 $

View File

@@ -1,7 +1,7 @@
# #
# Makefile # Makefile
# #
# $Id: //poco/1.4/Crypto/testsuite/Makefile#2 $ # $Id: //poco/1.4/Crypto/testsuite/Makefile#3 $
# #
# Makefile for Poco Crypto testsuite # Makefile for Poco Crypto testsuite
# #

View File

@@ -1,7 +1,7 @@
# #
# Makefile # Makefile
# #
# $Id: //poco/1.4/Data/MySQL/Makefile#2 $ # $Id: //poco/1.4/Data/MySQL/Makefile#3 $
# #
# Makefile for Poco MySQL # Makefile for Poco MySQL
# #

View File

@@ -1,7 +1,7 @@
# #
# Makefile # Makefile
# #
# $Id: //poco/1.4/Data/MySQL/testsuite/Makefile#2 $ # $Id: //poco/1.4/Data/MySQL/testsuite/Makefile#3 $
# #
# Makefile for Poco MySQL testsuite # Makefile for Poco MySQL testsuite
# #

View File

@@ -1,7 +1,7 @@
// //
// DataTypes.h // DataTypes.h
// //
// $Id: //poco/1.4/Data/ODBC/include/Poco/Data/ODBC/DataTypes.h#1 $ // $Id: //poco/1.4/Data/ODBC/include/Poco/Data/ODBC/DataTypes.h#2 $
// //
// Library: Data/ODBC // Library: Data/ODBC
// Package: ODBC // Package: ODBC

View File

@@ -1,7 +1,7 @@
// //
// EnvironmentHandle.h // EnvironmentHandle.h
// //
// $Id: //poco/1.4/Data/ODBC/include/Poco/Data/ODBC/EnvironmentHandle.h#1 $ // $Id: //poco/1.4/Data/ODBC/include/Poco/Data/ODBC/EnvironmentHandle.h#2 $
// //
// Library: Data/ODBC // Library: Data/ODBC
// Package: ODBC // Package: ODBC

View File

@@ -1,7 +1,7 @@
# #
# Makefile # Makefile
# #
# $Id: //poco/Main/Data/ODBC/testsuite/Makefile#1 $ # $Id: //poco/1.4/Data/ODBC/testsuite/Makefile#3 $
# #
# Makefile for Poco SQLite testsuite # Makefile for Poco SQLite testsuite
# #

View File

@@ -1,7 +1,7 @@
# #
# Makefile # Makefile
# #
# $Id: //poco/1.4/Foundation/testsuite/Makefile#1 $ # $Id: //poco/1.4/Foundation/testsuite/Makefile#2 $
# #
# Makefile for Poco Foundation testsuite # Makefile for Poco Foundation testsuite
# #

View File

@@ -1,7 +1,7 @@
// //
// HTTPFixedLengthStream.h // HTTPFixedLengthStream.h
// //
// $Id: //poco/1.4/Net/include/Poco/Net/HTTPFixedLengthStream.h#1 $ // $Id: //poco/1.4/Net/include/Poco/Net/HTTPFixedLengthStream.h#3 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
@@ -63,7 +63,13 @@ class Net_API HTTPFixedLengthStreamBuf: public HTTPBasicStreamBuf
public: public:
typedef HTTPBasicStreamBuf::openmode openmode; typedef HTTPBasicStreamBuf::openmode openmode;
HTTPFixedLengthStreamBuf(HTTPSession& session, std::streamsize length, openmode mode); #if defined(POCO_HAVE_INT64)
typedef Poco::Int64 ContentLength;
#else
typedef std::streamsize ContentLength;
#endif
HTTPFixedLengthStreamBuf(HTTPSession& session, ContentLength length, openmode mode);
~HTTPFixedLengthStreamBuf(); ~HTTPFixedLengthStreamBuf();
protected: protected:
@@ -72,8 +78,8 @@ protected:
private: private:
HTTPSession& _session; HTTPSession& _session;
std::streamsize _length; ContentLength _length;
std::streamsize _count; ContentLength _count;
}; };
@@ -81,7 +87,7 @@ class Net_API HTTPFixedLengthIOS: public virtual std::ios
/// The base class for HTTPFixedLengthInputStream. /// The base class for HTTPFixedLengthInputStream.
{ {
public: public:
HTTPFixedLengthIOS(HTTPSession& session, std::streamsize length, HTTPFixedLengthStreamBuf::openmode mode); HTTPFixedLengthIOS(HTTPSession& session, HTTPFixedLengthStreamBuf::ContentLength length, HTTPFixedLengthStreamBuf::openmode mode);
~HTTPFixedLengthIOS(); ~HTTPFixedLengthIOS();
HTTPFixedLengthStreamBuf* rdbuf(); HTTPFixedLengthStreamBuf* rdbuf();
@@ -94,7 +100,7 @@ class Net_API HTTPFixedLengthInputStream: public HTTPFixedLengthIOS, public std:
/// This class is for internal use by HTTPSession only. /// This class is for internal use by HTTPSession only.
{ {
public: public:
HTTPFixedLengthInputStream(HTTPSession& session, std::streamsize length); HTTPFixedLengthInputStream(HTTPSession& session, HTTPFixedLengthStreamBuf::ContentLength length);
~HTTPFixedLengthInputStream(); ~HTTPFixedLengthInputStream();
void* operator new(std::size_t size); void* operator new(std::size_t size);
@@ -109,7 +115,7 @@ class Net_API HTTPFixedLengthOutputStream: public HTTPFixedLengthIOS, public std
/// This class is for internal use by HTTPSession only. /// This class is for internal use by HTTPSession only.
{ {
public: public:
HTTPFixedLengthOutputStream(HTTPSession& session, std::streamsize length); HTTPFixedLengthOutputStream(HTTPSession& session, HTTPFixedLengthStreamBuf::ContentLength length);
~HTTPFixedLengthOutputStream(); ~HTTPFixedLengthOutputStream();
void* operator new(std::size_t size); void* operator new(std::size_t size);

View File

@@ -1,7 +1,7 @@
// //
// HTTPMessage.h // HTTPMessage.h
// //
// $Id: //poco/1.4/Net/include/Poco/Net/HTTPMessage.h#3 $ // $Id: //poco/1.4/Net/include/Poco/Net/HTTPMessage.h#4 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
@@ -95,6 +95,9 @@ public:
/// always returns a 64-bit integer for content length. /// always returns a 64-bit integer for content length.
#endif // defined(POCO_HAVE_INT64) #endif // defined(POCO_HAVE_INT64)
bool hasContentLength() const;
/// Returns true iff a Content-Length header is present.
void setTransferEncoding(const std::string& transferEncoding); void setTransferEncoding(const std::string& transferEncoding);
/// Sets the transfer encoding for this message. /// Sets the transfer encoding for this message.
/// ///
@@ -192,6 +195,12 @@ inline const std::string& HTTPMessage::getVersion() const
} }
inline bool HTTPMessage::hasContentLength() const
{
return has(CONTENT_LENGTH);
}
} } // namespace Poco::Net } } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
// //
// HTTPServerRequestImpl.h // HTTPServerRequestImpl.h
// //
// $Id: //poco/1.4/Net/include/Poco/Net/HTTPServerRequestImpl.h#1 $ // $Id: //poco/1.4/Net/include/Poco/Net/HTTPServerRequestImpl.h#2 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
@@ -42,6 +42,7 @@
#include "Poco/Net/Net.h" #include "Poco/Net/Net.h"
#include "Poco/Net/HTTPServerRequest.h" #include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponseImpl.h"
#include "Poco/Net/SocketAddress.h" #include "Poco/Net/SocketAddress.h"
#include "Poco/AutoPtr.h" #include "Poco/AutoPtr.h"
#include <istream> #include <istream>
@@ -64,7 +65,7 @@ class Net_API HTTPServerRequestImpl: public HTTPServerRequest
/// handleRequest() method of HTTPRequestHandler. /// handleRequest() method of HTTPRequestHandler.
{ {
public: public:
HTTPServerRequestImpl(HTTPServerResponse& response, HTTPServerSession& session, HTTPServerParams* pParams); HTTPServerRequestImpl(HTTPServerResponseImpl& response, HTTPServerSession& session, HTTPServerParams* pParams);
/// Creates the HTTPServerRequestImpl, using the /// Creates the HTTPServerRequestImpl, using the
/// given HTTPServerSession. /// given HTTPServerSession.
@@ -105,7 +106,7 @@ protected:
static const std::string EXPECT; static const std::string EXPECT;
private: private:
HTTPServerResponse& _response; HTTPServerResponseImpl& _response;
HTTPServerSession& _session; HTTPServerSession& _session;
std::istream* _pStream; std::istream* _pStream;
Poco::AutoPtr<HTTPServerParams> _pParams; Poco::AutoPtr<HTTPServerParams> _pParams;

View File

@@ -1,7 +1,7 @@
// //
// HTTPServerResponseImpl.h // HTTPServerResponseImpl.h
// //
// $Id: //poco/1.4/Net/include/Poco/Net/HTTPServerResponseImpl.h#1 $ // $Id: //poco/1.4/Net/include/Poco/Net/HTTPServerResponseImpl.h#2 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
@@ -49,7 +49,7 @@ namespace Net {
class HTTPServerSession; class HTTPServerSession;
class HTTPCookie; class HTTPServerRequestImpl;
class Net_API HTTPServerResponseImpl: public HTTPServerResponse class Net_API HTTPServerResponseImpl: public HTTPServerResponse
@@ -128,9 +128,15 @@ public:
bool sent() const; bool sent() const;
/// Returns true if the response (header) has been sent. /// Returns true if the response (header) has been sent.
protected:
void attachRequest(HTTPServerRequestImpl* pRequest);
private: private:
HTTPServerSession& _session; HTTPServerSession& _session;
HTTPServerRequestImpl* _pRequest;
std::ostream* _pStream; std::ostream* _pStream;
friend class HTTPServerRequestImpl;
}; };
@@ -143,6 +149,12 @@ inline bool HTTPServerResponseImpl::sent() const
} }
inline void HTTPServerResponseImpl::attachRequest(HTTPServerRequestImpl* pRequest)
{
_pRequest = pRequest;
}
} } // namespace Poco::Net } } // namespace Poco::Net

View File

@@ -1,7 +1,7 @@
// //
// SocketAddress.h // SocketAddress.h
// //
// $Id: //poco/1.4/Net/include/Poco/Net/SocketAddress.h#2 $ // $Id: //poco/1.4/Net/include/Poco/Net/SocketAddress.h#3 $
// //
// Library: Net // Library: Net
// Package: NetCore // Package: NetCore

View File

@@ -1,7 +1,7 @@
// //
// HTTPClientSession.cpp // HTTPClientSession.cpp
// //
// $Id: //poco/1.4/Net/src/HTTPClientSession.cpp#6 $ // $Id: //poco/1.4/Net/src/HTTPClientSession.cpp#7 $
// //
// Library: Net // Library: Net
// Package: HTTPClient // Package: HTTPClient
@@ -223,11 +223,15 @@ std::ostream& HTTPClientSession::sendRequest(HTTPRequest& request)
request.write(hos); request.write(hos);
_pRequestStream = new HTTPChunkedOutputStream(*this); _pRequestStream = new HTTPChunkedOutputStream(*this);
} }
else if (request.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH) else if (request.hasContentLength())
{ {
Poco::CountingOutputStream cs; Poco::CountingOutputStream cs;
request.write(cs); request.write(cs);
#if POCO_HAVE_INT64
_pRequestStream = new HTTPFixedLengthOutputStream(*this, request.getContentLength64() + cs.chars());
#else
_pRequestStream = new HTTPFixedLengthOutputStream(*this, request.getContentLength() + cs.chars()); _pRequestStream = new HTTPFixedLengthOutputStream(*this, request.getContentLength() + cs.chars());
#endif
request.write(*_pRequestStream); request.write(*_pRequestStream);
} }
else if (request.getMethod() != HTTPRequest::HTTP_PUT && request.getMethod() != HTTPRequest::HTTP_POST) else if (request.getMethod() != HTTPRequest::HTTP_PUT && request.getMethod() != HTTPRequest::HTTP_POST)
@@ -284,12 +288,16 @@ std::istream& HTTPClientSession::receiveResponse(HTTPResponse& response)
_mustReconnect = getKeepAlive() && !response.getKeepAlive(); _mustReconnect = getKeepAlive() && !response.getKeepAlive();
if (!_expectResponseBody) if (!_expectResponseBody || response.getStatus() < 200 || response.getStatus() == HTTPResponse::HTTP_NO_CONTENT || response.getStatus() == HTTPResponse::HTTP_NOT_MODIFIED)
_pResponseStream = new HTTPFixedLengthInputStream(*this, 0); _pResponseStream = new HTTPFixedLengthInputStream(*this, 0);
else if (response.getChunkedTransferEncoding()) else if (response.getChunkedTransferEncoding())
_pResponseStream = new HTTPChunkedInputStream(*this); _pResponseStream = new HTTPChunkedInputStream(*this);
else if (response.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH) else if (response.hasContentLength())
#if defined(POCO_HAVE_INT64)
_pResponseStream = new HTTPFixedLengthInputStream(*this, response.getContentLength64());
#else
_pResponseStream = new HTTPFixedLengthInputStream(*this, response.getContentLength()); _pResponseStream = new HTTPFixedLengthInputStream(*this, response.getContentLength());
#endif
else else
_pResponseStream = new HTTPInputStream(*this); _pResponseStream = new HTTPInputStream(*this);

View File

@@ -1,7 +1,7 @@
// //
// HTTPFixedLengthStream.cpp // HTTPFixedLengthStream.cpp
// //
// $Id: //poco/1.4/Net/src/HTTPFixedLengthStream.cpp#1 $ // $Id: //poco/1.4/Net/src/HTTPFixedLengthStream.cpp#3 $
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
@@ -50,7 +50,7 @@ namespace Net {
// //
HTTPFixedLengthStreamBuf::HTTPFixedLengthStreamBuf(HTTPSession& session, std::streamsize length, openmode mode): HTTPFixedLengthStreamBuf::HTTPFixedLengthStreamBuf(HTTPSession& session, ContentLength length, openmode mode):
HTTPBasicStreamBuf(HTTPBufferAllocator::BUFFER_SIZE, mode), HTTPBasicStreamBuf(HTTPBufferAllocator::BUFFER_SIZE, mode),
_session(session), _session(session),
_length(length), _length(length),
@@ -70,7 +70,7 @@ int HTTPFixedLengthStreamBuf::readFromDevice(char* buffer, std::streamsize lengt
if (_count < _length) if (_count < _length)
{ {
if (_count + length > _length) if (_count + length > _length)
length = _length - _count; length = static_cast<std::streamsize>(_length - _count);
n = _session.read(buffer, length); n = _session.read(buffer, length);
if (n > 0) _count += n; if (n > 0) _count += n;
} }
@@ -84,7 +84,7 @@ int HTTPFixedLengthStreamBuf::writeToDevice(const char* buffer, std::streamsize
if (_count < _length) if (_count < _length)
{ {
if (_count + length > _length) if (_count + length > _length)
length = _length - _count; length = static_cast<std::streamsize>(_length - _count);
n = _session.write(buffer, length); n = _session.write(buffer, length);
if (n > 0) _count += n; if (n > 0) _count += n;
} }
@@ -97,7 +97,7 @@ int HTTPFixedLengthStreamBuf::writeToDevice(const char* buffer, std::streamsize
// //
HTTPFixedLengthIOS::HTTPFixedLengthIOS(HTTPSession& session, std::streamsize length, HTTPFixedLengthStreamBuf::openmode mode): HTTPFixedLengthIOS::HTTPFixedLengthIOS(HTTPSession& session, HTTPFixedLengthStreamBuf::ContentLength length, HTTPFixedLengthStreamBuf::openmode mode):
_buf(session, length, mode) _buf(session, length, mode)
{ {
poco_ios_init(&_buf); poco_ios_init(&_buf);
@@ -130,7 +130,7 @@ HTTPFixedLengthStreamBuf* HTTPFixedLengthIOS::rdbuf()
Poco::MemoryPool HTTPFixedLengthInputStream::_pool(sizeof(HTTPFixedLengthInputStream)); Poco::MemoryPool HTTPFixedLengthInputStream::_pool(sizeof(HTTPFixedLengthInputStream));
HTTPFixedLengthInputStream::HTTPFixedLengthInputStream(HTTPSession& session, std::streamsize length): HTTPFixedLengthInputStream::HTTPFixedLengthInputStream(HTTPSession& session, HTTPFixedLengthStreamBuf::ContentLength length):
HTTPFixedLengthIOS(session, length, std::ios::in), HTTPFixedLengthIOS(session, length, std::ios::in),
std::istream(&_buf) std::istream(&_buf)
{ {
@@ -162,7 +162,7 @@ void HTTPFixedLengthInputStream::operator delete(void* ptr)
Poco::MemoryPool HTTPFixedLengthOutputStream::_pool(sizeof(HTTPFixedLengthOutputStream)); Poco::MemoryPool HTTPFixedLengthOutputStream::_pool(sizeof(HTTPFixedLengthOutputStream));
HTTPFixedLengthOutputStream::HTTPFixedLengthOutputStream(HTTPSession& session, std::streamsize length): HTTPFixedLengthOutputStream::HTTPFixedLengthOutputStream(HTTPSession& session, HTTPFixedLengthStreamBuf::ContentLength length):
HTTPFixedLengthIOS(session, length, std::ios::out), HTTPFixedLengthIOS(session, length, std::ios::out),
std::ostream(&_buf) std::ostream(&_buf)
{ {

View File

@@ -1,7 +1,7 @@
// //
// HTTPServerConnection.cpp // HTTPServerConnection.cpp
// //
// $Id: //poco/1.4/Net/src/HTTPServerConnection.cpp#5 $ // $Id: //poco/1.4/Net/src/HTTPServerConnection.cpp#7 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
@@ -83,7 +83,7 @@ void HTTPServerConnection::run()
{ {
HTTPServerResponseImpl response(session); HTTPServerResponseImpl response(session);
HTTPServerRequestImpl request(response, session, _pParams); HTTPServerRequestImpl request(response, session, _pParams);
Poco::Timestamp now; Poco::Timestamp now;
response.setDate(now); response.setDate(now);
response.setVersion(request.getVersion()); response.setVersion(request.getVersion());
@@ -149,7 +149,14 @@ void HTTPServerConnection::onServerStopped(const bool& abortCurrent)
{ {
try try
{ {
// Note: On Windows, select() will not return if one of its socket is being
// shut down. Therefore we have to call close(), which works better.
// On other platforms, we do the more graceful thing.
#if defined(_WIN32)
socket().close(); socket().close();
#else
socket().shutdown();
#endif
} }
catch (...) catch (...)
{ {
@@ -161,7 +168,11 @@ void HTTPServerConnection::onServerStopped(const bool& abortCurrent)
try try
{ {
#if defined(_WIN32)
socket().close(); socket().close();
#else
socket().shutdown();
#endif
} }
catch (...) catch (...)
{ {

View File

@@ -1,7 +1,7 @@
// //
// HTTPServerRequestImpl.cpp // HTTPServerRequestImpl.cpp
// //
// $Id: //poco/1.4/Net/src/HTTPServerRequestImpl.cpp#1 $ // $Id: //poco/1.4/Net/src/HTTPServerRequestImpl.cpp#3 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
@@ -35,6 +35,7 @@
#include "Poco/Net/HTTPServerRequestImpl.h" #include "Poco/Net/HTTPServerRequestImpl.h"
#include "Poco/Net/HTTPServerResponseImpl.h"
#include "Poco/Net/HTTPServerSession.h" #include "Poco/Net/HTTPServerSession.h"
#include "Poco/Net/HTTPHeaderStream.h" #include "Poco/Net/HTTPHeaderStream.h"
#include "Poco/Net/HTTPStream.h" #include "Poco/Net/HTTPStream.h"
@@ -54,12 +55,14 @@ namespace Net {
const std::string HTTPServerRequestImpl::EXPECT("Expect"); const std::string HTTPServerRequestImpl::EXPECT("Expect");
HTTPServerRequestImpl::HTTPServerRequestImpl(HTTPServerResponse& response, HTTPServerSession& session, HTTPServerParams* pParams): HTTPServerRequestImpl::HTTPServerRequestImpl(HTTPServerResponseImpl& response, HTTPServerSession& session, HTTPServerParams* pParams):
_response(response), _response(response),
_session(session), _session(session),
_pStream(0), _pStream(0),
_pParams(pParams, true) _pParams(pParams, true)
{ {
response.attachRequest(this);
HTTPHeaderInputStream hs(session); HTTPHeaderInputStream hs(session);
read(hs); read(hs);
@@ -69,8 +72,12 @@ HTTPServerRequestImpl::HTTPServerRequestImpl(HTTPServerResponse& response, HTTPS
if (getChunkedTransferEncoding()) if (getChunkedTransferEncoding())
_pStream = new HTTPChunkedInputStream(session); _pStream = new HTTPChunkedInputStream(session);
else if (getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH) else if (hasContentLength())
#if defined(POCO_HAVE_INT64)
_pStream = new HTTPFixedLengthInputStream(session, getContentLength64());
#else
_pStream = new HTTPFixedLengthInputStream(session, getContentLength()); _pStream = new HTTPFixedLengthInputStream(session, getContentLength());
#endif
else if (getMethod() == HTTPRequest::HTTP_GET || getMethod() == HTTPRequest::HTTP_HEAD) else if (getMethod() == HTTPRequest::HTTP_GET || getMethod() == HTTPRequest::HTTP_HEAD)
_pStream = new HTTPFixedLengthInputStream(session, 0); _pStream = new HTTPFixedLengthInputStream(session, 0);
else else

View File

@@ -1,7 +1,7 @@
// //
// HTTPServerResponseImpl.cpp // HTTPServerResponseImpl.cpp
// //
// $Id: //poco/1.4/Net/src/HTTPServerResponseImpl.cpp#2 $ // $Id: //poco/1.4/Net/src/HTTPServerResponseImpl.cpp#4 $
// //
// Library: Net // Library: Net
// Package: HTTPServer // Package: HTTPServer
@@ -35,6 +35,7 @@
#include "Poco/Net/HTTPServerResponseImpl.h" #include "Poco/Net/HTTPServerResponseImpl.h"
#include "Poco/Net/HTTPServerRequestImpl.h"
#include "Poco/Net/HTTPServerSession.h" #include "Poco/Net/HTTPServerSession.h"
#include "Poco/Net/HTTPHeaderStream.h" #include "Poco/Net/HTTPHeaderStream.h"
#include "Poco/Net/HTTPStream.h" #include "Poco/Net/HTTPStream.h"
@@ -66,6 +67,7 @@ namespace Net {
HTTPServerResponseImpl::HTTPServerResponseImpl(HTTPServerSession& session): HTTPServerResponseImpl::HTTPServerResponseImpl(HTTPServerSession& session):
_session(session), _session(session),
_pRequest(0),
_pStream(0) _pStream(0)
{ {
} }
@@ -88,17 +90,31 @@ std::ostream& HTTPServerResponseImpl::send()
{ {
poco_assert (!_pStream); poco_assert (!_pStream);
if (getChunkedTransferEncoding()) if (_pRequest && _pRequest->getMethod() == HTTPRequest::HTTP_HEAD ||
getStatus() < 200 ||
getStatus() == HTTPResponse::HTTP_NO_CONTENT ||
getStatus() == HTTPResponse::HTTP_NOT_MODIFIED)
{
Poco::CountingOutputStream cs;
write(cs);
_pStream = new HTTPFixedLengthOutputStream(_session, cs.chars());
write(*_pStream);
}
else if (getChunkedTransferEncoding())
{ {
HTTPHeaderOutputStream hs(_session); HTTPHeaderOutputStream hs(_session);
write(hs); write(hs);
_pStream = new HTTPChunkedOutputStream(_session); _pStream = new HTTPChunkedOutputStream(_session);
} }
else if (getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH) else if (hasContentLength())
{ {
Poco::CountingOutputStream cs; Poco::CountingOutputStream cs;
write(cs); write(cs);
#if defined(POCO_HAVE_INT64)
_pStream = new HTTPFixedLengthOutputStream(_session, getContentLength64() + cs.chars());
#else
_pStream = new HTTPFixedLengthOutputStream(_session, getContentLength() + cs.chars()); _pStream = new HTTPFixedLengthOutputStream(_session, getContentLength() + cs.chars());
#endif
write(*_pStream); write(*_pStream);
} }
else else
@@ -132,7 +148,10 @@ void HTTPServerResponseImpl::sendFile(const std::string& path, const std::string
{ {
_pStream = new HTTPHeaderOutputStream(_session); _pStream = new HTTPHeaderOutputStream(_session);
write(*_pStream); write(*_pStream);
StreamCopier::copyStream(istr, *_pStream); if (_pRequest && _pRequest->getMethod() != HTTPRequest::HTTP_HEAD)
{
StreamCopier::copyStream(istr, *_pStream);
}
} }
else throw OpenFileException(path); else throw OpenFileException(path);
} }
@@ -147,7 +166,10 @@ void HTTPServerResponseImpl::sendBuffer(const void* pBuffer, std::size_t length)
_pStream = new HTTPHeaderOutputStream(_session); _pStream = new HTTPHeaderOutputStream(_session);
write(*_pStream); write(*_pStream);
_pStream->write(static_cast<const char*>(pBuffer), static_cast<std::streamsize>(length)); if (_pRequest && _pRequest->getMethod() != HTTPRequest::HTTP_HEAD)
{
_pStream->write(static_cast<const char*>(pBuffer), static_cast<std::streamsize>(length));
}
} }

View File

@@ -1,7 +1,7 @@
// //
// SocketAddress.cpp // SocketAddress.cpp
// //
// $Id: //poco/1.4/Net/src/SocketAddress.cpp#5 $ // $Id: //poco/1.4/Net/src/SocketAddress.cpp#6 $
// //
// Library: Net // Library: Net
// Package: NetCore // Package: NetCore

View File

@@ -1,7 +1,7 @@
// //
// SocketImpl.cpp // SocketImpl.cpp
// //
// $Id: //poco/1.4/Net/src/SocketImpl.cpp#6 $ // $Id: //poco/1.4/Net/src/SocketImpl.cpp#7 $
// //
// Library: Net // Library: Net
// Package: Sockets // Package: Sockets
@@ -484,6 +484,7 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
FD_SET(sockfd, &fdExcept); FD_SET(sockfd, &fdExcept);
} }
Poco::Timespan remainingTime(timeout); Poco::Timespan remainingTime(timeout);
int errorCode;
int rc; int rc;
do do
{ {
@@ -492,7 +493,7 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
tv.tv_usec = (long) remainingTime.useconds(); tv.tv_usec = (long) remainingTime.useconds();
Poco::Timestamp start; Poco::Timestamp start;
rc = ::select(int(sockfd) + 1, &fdRead, &fdWrite, &fdExcept, &tv); rc = ::select(int(sockfd) + 1, &fdRead, &fdWrite, &fdExcept, &tv);
if (rc < 0 && lastError() == POCO_EINTR) if (rc < 0 && (errorCode = lastError()) == POCO_EINTR)
{ {
Poco::Timestamp end; Poco::Timestamp end;
Poco::Timespan waited = end - start; Poco::Timespan waited = end - start;
@@ -502,8 +503,8 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
remainingTime = 0; remainingTime = 0;
} }
} }
while (rc < 0 && lastError() == POCO_EINTR); while (rc < 0 && errorCode == POCO_EINTR);
if (rc < 0) error(); if (rc < 0) error(errorCode);
return rc > 0; return rc > 0;
#endif // POCO_HAVE_FD_EPOLL #endif // POCO_HAVE_FD_EPOLL

View File

@@ -12,14 +12,14 @@
// execute, and transmit the Software, and to prepare derivative works of the // execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and // must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
@@ -56,11 +56,11 @@ void IPAddressTest::testStringConv()
IPAddress ia1("127.0.0.1"); IPAddress ia1("127.0.0.1");
assert (ia1.family() == IPAddress::IPv4); assert (ia1.family() == IPAddress::IPv4);
assert (ia1.toString() == "127.0.0.1"); assert (ia1.toString() == "127.0.0.1");
IPAddress ia2("192.168.1.120"); IPAddress ia2("192.168.1.120");
assert (ia2.family() == IPAddress::IPv4); assert (ia2.family() == IPAddress::IPv4);
assert (ia2.toString() == "192.168.1.120"); assert (ia2.toString() == "192.168.1.120");
IPAddress ia3("255.255.255.255"); IPAddress ia3("255.255.255.255");
assert (ia3.family() == IPAddress::IPv4); assert (ia3.family() == IPAddress::IPv4);
assert (ia3.toString() == "255.255.255.255"); assert (ia3.toString() == "255.255.255.255");
@@ -77,11 +77,11 @@ void IPAddressTest::testStringConv6()
IPAddress ia1("1080:0:0:0:8:600:200A:425C"); IPAddress ia1("1080:0:0:0:8:600:200A:425C");
assert (ia1.family() == IPAddress::IPv6); assert (ia1.family() == IPAddress::IPv6);
assert (ia1.toString() == "1080::8:600:200A:425C"); assert (ia1.toString() == "1080::8:600:200A:425C");
IPAddress ia2("1080::8:600:200A:425C"); IPAddress ia2("1080::8:600:200A:425C");
assert (ia2.family() == IPAddress::IPv6); assert (ia2.family() == IPAddress::IPv6);
assert (ia2.toString() == "1080::8:600:200A:425C"); assert (ia2.toString() == "1080::8:600:200A:425C");
IPAddress ia3("::192.168.1.120"); IPAddress ia3("::192.168.1.120");
assert (ia3.family() == IPAddress::IPv6); assert (ia3.family() == IPAddress::IPv6);
assert (ia3.toString() == "::192.168.1.120"); assert (ia3.toString() == "::192.168.1.120");
@@ -97,7 +97,7 @@ void IPAddressTest::testParse()
{ {
IPAddress ip; IPAddress ip;
assert (IPAddress::tryParse("192.168.1.120", ip)); assert (IPAddress::tryParse("192.168.1.120", ip));
assert (!IPAddress::tryParse("192.168.1.280", ip)); assert (!IPAddress::tryParse("192.168.1.280", ip));
ip = IPAddress::parse("192.168.1.120"); ip = IPAddress::parse("192.168.1.120");
@@ -105,7 +105,7 @@ void IPAddressTest::testParse()
{ {
ip = IPAddress::parse("192.168.1.280"); ip = IPAddress::parse("192.168.1.280");
fail("bad address - must throw"); fail("bad address - must throw");
} }
catch (InvalidAddressException&) catch (InvalidAddressException&)
{ {
} }
@@ -128,7 +128,7 @@ void IPAddressTest::testClassification()
assert (!ip1.isSiteLocalMC()); assert (!ip1.isSiteLocalMC());
assert (!ip1.isOrgLocalMC()); assert (!ip1.isOrgLocalMC());
assert (!ip1.isGlobalMC()); assert (!ip1.isGlobalMC());
IPAddress ip2("255.255.255.255"); // broadcast IPAddress ip2("255.255.255.255"); // broadcast
assert (!ip2.isWildcard()); assert (!ip2.isWildcard());
assert (ip2.isBroadcast()); assert (ip2.isBroadcast());
@@ -143,7 +143,7 @@ void IPAddressTest::testClassification()
assert (!ip2.isSiteLocalMC()); assert (!ip2.isSiteLocalMC());
assert (!ip2.isOrgLocalMC()); assert (!ip2.isOrgLocalMC());
assert (!ip2.isGlobalMC()); assert (!ip2.isGlobalMC());
IPAddress ip3("127.0.0.1"); // loopback IPAddress ip3("127.0.0.1"); // loopback
assert (!ip3.isWildcard()); assert (!ip3.isWildcard());
assert (!ip3.isBroadcast()); assert (!ip3.isBroadcast());
@@ -332,7 +332,7 @@ void IPAddressTest::testClassification6()
assert (!ip1.isSiteLocalMC()); assert (!ip1.isSiteLocalMC());
assert (!ip1.isOrgLocalMC()); assert (!ip1.isOrgLocalMC());
assert (!ip1.isGlobalMC()); assert (!ip1.isGlobalMC());
IPAddress ip3("::1"); // loopback IPAddress ip3("::1"); // loopback
assert (!ip3.isWildcard()); assert (!ip3.isWildcard());
assert (!ip3.isBroadcast()); assert (!ip3.isBroadcast());
@@ -442,7 +442,7 @@ void IPAddressTest::testMCClassification6()
assert (!ip2.isLinkLocalMC()); assert (!ip2.isLinkLocalMC());
assert (!ip2.isSiteLocalMC()); assert (!ip2.isSiteLocalMC());
assert (!ip2.isOrgLocalMC()); assert (!ip2.isOrgLocalMC());
assert (!ip2.isGlobalMC()); assert (!ip2.isGlobalMC());
IPAddress ip3("FF05:0:0:0:0:0:0:FB"); // site local unicast IPAddress ip3("FF05:0:0:0:0:0:0:FB"); // site local unicast
assert (!ip3.isWildcard()); assert (!ip3.isWildcard());
@@ -498,7 +498,7 @@ void IPAddressTest::testRelationals()
IPAddress ip2(ip1); IPAddress ip2(ip1);
IPAddress ip3; IPAddress ip3;
IPAddress ip4("10.0.0.138"); IPAddress ip4("10.0.0.138");
assert (ip1 != ip4); assert (ip1 != ip4);
assert (ip1 == ip2); assert (ip1 == ip2);
assert (!(ip1 != ip2)); assert (!(ip1 != ip2));
@@ -511,7 +511,7 @@ void IPAddressTest::testRelationals()
assert (!(ip1 <= ip4)); assert (!(ip1 <= ip4));
assert (!(ip4 > ip1)); assert (!(ip4 > ip1));
assert (!(ip4 >= ip1)); assert (!(ip4 >= ip1));
ip3 = ip1; ip3 = ip1;
assert (ip1 == ip3); assert (ip1 == ip3);
ip3 = ip4; ip3 = ip4;

View File

@@ -1,7 +1,7 @@
// //
// SocketAddressTest.cpp // SocketAddressTest.cpp
// //
// $Id: //poco/1.4/Net/testsuite/src/SocketAddressTest.cpp#2 $ // $Id: //poco/1.4/Net/testsuite/src/SocketAddressTest.cpp#3 $
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.

View File

@@ -1,7 +1,7 @@
// //
// SocketAddressTest.h // SocketAddressTest.h
// //
// $Id: //poco/1.4/Net/testsuite/src/SocketAddressTest.h#1 $ // $Id: //poco/1.4/Net/testsuite/src/SocketAddressTest.h#2 $
// //
// Definition of the SocketAddressTest class. // Definition of the SocketAddressTest class.
// //

View File

@@ -8,7 +8,6 @@
include $(POCO_BASE)/build/rules/global include $(POCO_BASE)/build/rules/global
SYSLIBS += -lc -lm
objects = Page PageReader \ objects = Page PageReader \
CodeWriter ApacheCodeWriter OSPCodeWriter \ CodeWriter ApacheCodeWriter OSPCodeWriter \
PageCompiler PageCompiler

View File

@@ -9,7 +9,7 @@
include $(POCO_BASE)/build/rules/global include $(POCO_BASE)/build/rules/global
# Where to find the PageCompiler executable # Where to find the PageCompiler executable
PAGECOMPILER = $(POCO_BASE)/PageCompiler/bin/$(POCO_HOST_OSNAME)/$(POCO_HOST_OSARCH)/cpspc$(OSARCH_POSTFIX) PAGECOMPILER = $(POCO_BASE)/PageCompiler/bin/$(POCO_HOST_OSNAME)/$(POCO_HOST_OSARCH)/cpspc
objects = HTTPTimeServerApp TimeHandler objects = HTTPTimeServerApp TimeHandler

View File

@@ -1,7 +1,7 @@
// //
// CharacterData.cpp // CharacterData.cpp
// //
// $Id: //poco/1.4/XML/src/CharacterData.cpp#1 $ // $Id: //poco/1.4/XML/src/CharacterData.cpp#2 $
// //
// Library: XML // Library: XML
// Package: DOM // Package: DOM
@@ -64,9 +64,16 @@ CharacterData::~CharacterData()
void CharacterData::setData(const XMLString& data) void CharacterData::setData(const XMLString& data)
{ {
XMLString oldData = getData(); if (events())
_data = data; {
if (events()) dispatchCharacterDataModified(oldData, _data); XMLString oldData = _data;
_data = data;
dispatchCharacterDataModified(oldData, _data);
}
else
{
_data = data;
}
} }
@@ -81,9 +88,16 @@ XMLString CharacterData::substringData(unsigned long offset, unsigned long count
void CharacterData::appendData(const XMLString& arg) void CharacterData::appendData(const XMLString& arg)
{ {
XMLString oldData = _data; if (events())
_data.append(arg); {
if (events()) dispatchCharacterDataModified(oldData, _data); XMLString oldData = _data;
_data.append(arg);
dispatchCharacterDataModified(oldData, _data);
}
else
{
_data.append(arg);
}
} }
@@ -92,9 +106,16 @@ void CharacterData::insertData(unsigned long offset, const XMLString& arg)
if (offset > _data.length()) if (offset > _data.length())
throw DOMException(DOMException::INDEX_SIZE_ERR); throw DOMException(DOMException::INDEX_SIZE_ERR);
XMLString oldData = _data; if (events())
_data.insert(offset, arg); {
if (events()) dispatchCharacterDataModified(oldData, _data); XMLString oldData = _data;
_data.insert(offset, arg);
dispatchCharacterDataModified(oldData, _data);
}
else
{
_data.insert(offset, arg);
}
} }
@@ -103,9 +124,14 @@ void CharacterData::deleteData(unsigned long offset, unsigned long count)
if (offset >= _data.length()) if (offset >= _data.length())
throw DOMException(DOMException::INDEX_SIZE_ERR); throw DOMException(DOMException::INDEX_SIZE_ERR);
XMLString oldData = _data; if (events())
_data.replace(offset, count, EMPTY_STRING); {
if (events()) dispatchCharacterDataModified(oldData, _data); XMLString oldData = _data;
_data.replace(offset, count, EMPTY_STRING);
dispatchCharacterDataModified(oldData, _data);
}
else
_data.replace(offset, count, EMPTY_STRING);
} }
@@ -114,9 +140,16 @@ void CharacterData::replaceData(unsigned long offset, unsigned long count, const
if (offset >= _data.length()) if (offset >= _data.length())
throw DOMException(DOMException::INDEX_SIZE_ERR); throw DOMException(DOMException::INDEX_SIZE_ERR);
XMLString oldData = _data; if (events())
_data.replace(offset, count, arg); {
if (events()) dispatchCharacterDataModified(oldData, _data); XMLString oldData = _data;
_data.replace(offset, count, arg);
dispatchCharacterDataModified(oldData, _data);
}
else
{
_data.replace(offset, count, arg);
}
} }