MCPcopy Create free account
hub / github.com/KikoPlayProject/KikoPlay / read

Method read

LANServer/httpserver/httpconnectionhandler.cpp:167–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167void HttpConnectionHandler::read()
168{
169 // The loop adds support for HTTP pipelinig
170 while (socket->bytesAvailable())
171 {
172 #ifdef SUPERVERBOSE
173 Logger::logger()->log(Logger::LANServer, "HttpConnectionHandler (%p): read input",static_cast<void*>(this));
174 #endif
175
176 // Create new HttpRequest object if necessary
177 if (!currentRequest)
178 {
179 currentRequest=new HttpRequest(settings);
180 }
181
182 // Collect data for the request object
183 while (socket->bytesAvailable() && currentRequest->getStatus()!=HttpRequest::complete && currentRequest->getStatus()!=HttpRequest::abort)
184 {
185 currentRequest->readFromSocket(socket);
186 if (currentRequest->getStatus()==HttpRequest::waitForBody)
187 {
188 // Restart timer for read timeout, otherwise it would
189 // expire during large file uploads.
190 int readTimeout=settings->value("readTimeout",10000).toInt();
191 readTimer.start(readTimeout);
192 }
193 }
194
195 // If the request is aborted, return error message and close the connection
196 if (currentRequest->getStatus()==HttpRequest::abort)
197 {
198 socket->write("HTTP/1.1 413 entity too large\r\nConnection: close\r\n\r\n413 Entity too large\r\n");
199 while(socket->bytesToWrite()) socket->waitForBytesWritten();
200 socket->disconnectFromHost();
201 delete currentRequest;
202 currentRequest=nullptr;
203 return;
204 }
205
206 // If the request is complete, let the request mapper dispatch it
207 if (currentRequest->getStatus()==HttpRequest::complete)
208 {
209 readTimer.stop();
210#ifdef QT_DEBUG
211 Logger::logger()->log(Logger::LANServer, "HttpConnectionHandler (%p): received request",static_cast<void*>(this));
212#endif
213
214 // Copy the Connection:close header to the response
215 HttpResponse response(socket);
216 bool closeConnection=QString::compare(currentRequest->getHeader("Connection"),"close",Qt::CaseInsensitive)==0;
217 if (closeConnection)
218 {
219 response.setHeader("Connection","close");
220 }
221
222 // In case of HTTP 1.0 protocol add the Connection:close header.
223 // This ensures that the HttpResponse does not activate chunked mode, which is not spported by HTTP 1.0.
224 else

Callers 3

processFileMethod · 0.45
readBodyMethod · 0.45
serviceMethod · 0.45

Calls 15

compareFunction · 0.85
logMethod · 0.80
getStatusMethod · 0.80
readFromSocketMethod · 0.80
valueMethod · 0.80
getHeaderMethod · 0.80
setHeaderMethod · 0.80
hasSentLastPartMethod · 0.80
getHeadersMethod · 0.80
startMethod · 0.45
writeMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected