1//
2// HTTPServerRequestImpl.cpp
3//
4// Library: Net
5// Package: HTTPServer
6// Module: HTTPServerRequestImpl
7//
8// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/Net/HTTPServerRequestImpl.h"
16#include "Poco/Net/HTTPServerResponseImpl.h"
17#include "Poco/Net/HTTPServerSession.h"
18#include "Poco/Net/HTTPHeaderStream.h"
19#include "Poco/Net/HTTPStream.h"
20#include "Poco/Net/HTTPFixedLengthStream.h"
21#include "Poco/Net/HTTPChunkedStream.h"
22#include "Poco/Net/HTTPServerParams.h"
23#include "Poco/Net/StreamSocket.h"
24#include "Poco/String.h"
25
26
27using Poco::icompare;
28
29
30namespace Poco {
31namespace Net {
32
33
34HTTPServerRequestImpl::HTTPServerRequestImpl(HTTPServerResponseImpl& response, HTTPServerSession& session, HTTPServerParams* pParams):
35 _response(response),
36 _session(session),
37 _pStream(0),
38 _pParams(pParams, true)
39{
40 response.attachRequest(this);
41
42 HTTPHeaderInputStream hs(session);
43 read(hs);
44
45 // Now that we know socket is still connected, obtain addresses
46 _clientAddress = session.clientAddress();
47 _serverAddress = session.serverAddress();
48
49 if (getChunkedTransferEncoding())
50 _pStream = new HTTPChunkedInputStream(session);
51 else if (hasContentLength())
52#if defined(POCO_HAVE_INT64)
53 _pStream = new HTTPFixedLengthInputStream(session, getContentLength64());
54#else
55 _pStream = new HTTPFixedLengthInputStream(session, getContentLength());
56#endif
57 else if (getMethod() == HTTPRequest::HTTP_GET || getMethod() == HTTPRequest::HTTP_HEAD || getMethod() == HTTPRequest::HTTP_DELETE)
58 _pStream = new HTTPFixedLengthInputStream(session, 0);
59 else
60 _pStream = new HTTPInputStream(session);
61}
62
63
64HTTPServerRequestImpl::~HTTPServerRequestImpl()
65{
66 delete _pStream;
67}
68
69
70bool HTTPServerRequestImpl::secure() const
71{
72 return _session.socket().secure();
73}
74
75
76StreamSocket& HTTPServerRequestImpl::socket()
77{
78 return _session.socket();
79}
80
81
82StreamSocket HTTPServerRequestImpl::detachSocket()
83{
84 return _session.detachSocket();
85}
86
87
88} } // namespace Poco::Net
89