Remove dynamic exceptions
[anna.git] / source / http / parser / ReadChunkTrailers.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/ReadChunkTrailers.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  *
20  * Una vez que se ha encontrado el "0" que indica el final de los bloques
21  * del mensaje particioinado, pueden venir más headers, él fin del
22  * mensaje estará indicado por una línea en blanco.
23  *
24    HTTP/1.1 200 OK
25    Date: Fri, 31 Dec 1999 23:59:59 GMT
26    Content-Type: text/plain
27    Transfer-Encoding: chunked
28
29    1a; ignore-stuff-here
30    abcdefghijklmnopqrstuvwxyz
31    10
32    1234567890abcdef
33    0
34    some-footer: some-value
35    another-footer: another-value
36
37    464: 4a 61 6e 20 31 39 39 35 20 32 32 3a 30 30 3a 30   Jan 1995 22:00:0
38    480: 30 20 47 4d 54 0d 0a 43 6f 6e 74 65 6e 74 2d 54   0 GMT..Content-T
39    496: 79 70 65 3a 20 74 65 78 74 2f 68 74 6d 6c 0d 0a   ype: text/html..
40    512: 54 72 61 6e 73 66 65 72 2d 65 6e 63 6f 64 69 6e   Transfer-encodin
41    528: 67 3a 20 63 68 75 6e 6b 65 64 0d 0a 43 6f 6e 6e   g: chunked..Conn
42    544: 65 63 74 69 6f 6e 3a 20 4b 65 65 70 2d 41 6c 69   ection: Keep-Ali
43    560: 76 65 0d 0a 0d 0a 35 34 20 20 20 20 20 0d 0a 3c   ve....54     ..<     <================= ojo
44    576: 21 2d 2d 20 6c 30 37 2e 6d 65 6d 62 65 72 2e 75   !-- l07.member.u
45    592: 6b 6c 2e 79 61 68 6f 6f 2e 63 6f 6d 20 75 6e 63   kl.yahoo.com unc
46    608: 6f 6d 70 72 65 73 73 65 64 2f 63 68 75 6e 6b 65   ompressed/chunke
47    624: 64 20 57 65 64 20 53 65 70 20 20 33 20 31 30 3a   d Wed Sep  3 10:
48    640: 31 34 3a 31 31 20 47 4d 54 20 32 30 30 38 20 2d   14:11 GMT 2008 -
49    656: 2d 3e 0a 0d 0a 30 0d 0a 0d 0a                     ->...0....
50
51    (1) En el bloque de datos el sistema va acumulando los trozos de mensaje
52    recibidos por la red, ahora sólo hay que devolver el tamamño acumulado para
53    indicar que todo está completo.
54
55    Recordar que tenemos duplicada la información recibida por la red, en el 'slice'
56    y en el EncodedBlock que está asociado al http::Transport, y que será de donde
57    obtengamos el cuerpo del mensaje HTTP que progresaremos hacia el exterior.
58 */
59 int http::parser::ReadChunkTrailers::processLine(http::Transport& transport, const DataBlock& slice, const http::Token& line) const
60 noexcept(false) {
61   if(line.getSize() == 0) {            // (1)
62     setState(transport, ClassType::WaitMessage);
63     return line.calculeOffset(parser::Abstract::getFullMessage(transport)) + sizeEndOfLine;
64   }
65
66   return ReadHeader::processLine(transport, slice, line);
67 }
68