Remove dynamic exceptions
[anna.git] / source / http / parser / WaitEndOfHeader.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #include <anna/http/parser/WaitEndOfHeader.hpp>
10
11 #include <anna/http/Transport.hpp>
12 #include <anna/http/functions.hpp>
13 #include <anna/http/internal/defines.hpp>
14
15 using namespace std;
16 using namespace anna;
17
18 //----------------------------------------------------------------------------------------------------
19 // Recordar que sólo se llega a este estado en caso de haber encontrado el 'Content-Length'.
20 //----------------------------------------------------------------------------------------------------
21 int http::parser::WaitEndOfHeader::processLine(http::Transport& transport, const DataBlock& dataBlock, const http::Token& line) const
22 noexcept(false) {
23   /*
24    * Cuando en cuenta la última línea del mensaje calcula el tamaño total del mensaje.
25    * El Content-Length sólo informa sobre la longitud del bloque de datos, pero
26    * pero no tiene en cuenta lo que pueden ocupar las cabeceras y demás etiquetas.
27    */
28   if(line.getSize() == 0) {
29     const int bodyOffset = line.calculeOffset(dataBlock) + sizeEndOfLine;
30     transport.setBodyOffset(bodyOffset);
31     setState(transport, ClassType::WaitMessage);
32     return bodyOffset + transport.getContentLength();
33   }
34
35   return ReadHeader::processLine(transport, dataBlock, line);
36 }
37