1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 /*******************************************************************************
21  *  Includes
22  ******************************************************************************/
23 #include "networkrequest.h"
24 
25 #include <QtCore>
26 
27 /*******************************************************************************
28  *  Namespace
29  ******************************************************************************/
30 namespace librepcb {
31 
32 /*******************************************************************************
33  *  Constructors / Destructor
34  ******************************************************************************/
35 
NetworkRequest(const QUrl & url,const QByteArray & postData)36 NetworkRequest::NetworkRequest(const QUrl& url,
37                                const QByteArray& postData) noexcept
38   : NetworkRequestBase(url, postData), mReceivedData() {
39 }
40 
~NetworkRequest()41 NetworkRequest::~NetworkRequest() noexcept {
42 }
43 
44 /*******************************************************************************
45  *  Private Methods
46  ******************************************************************************/
47 
prepareRequest()48 void NetworkRequest::prepareRequest() {
49   mReceivedData.clear();
50 }
51 
finalizeRequest()52 void NetworkRequest::finalizeRequest() {
53   if (mReceivedData.size() > 100 * 1000 * 1000) {
54     throw RuntimeError(
55         __FILE__, __LINE__,
56         tr("The received content exceeds the 100MB size limit."));
57   }
58 }
59 
emitSuccessfullyFinishedSignals()60 void NetworkRequest::emitSuccessfullyFinishedSignals() noexcept {
61   emit dataReceived(mReceivedData);
62 }
63 
fetchNewData()64 void NetworkRequest::fetchNewData() noexcept {
65   QByteArray data = mReply->readAll();
66   if (mReceivedData.size() <= 100 * 1000 * 1000) {
67     mReceivedData.append(data);
68   }
69 }
70 
71 /*******************************************************************************
72  *  End of File
73  ******************************************************************************/
74 
75 }  // namespace librepcb
76