http_box/http1/
parser_error.rs

1// +-----------------------------------------------------------------------------------------------+
2// | Copyright 2016 Sean Kerr                                                                      |
3// |                                                                                               |
4// | Licensed under the Apache License, Version 2.0 (the "License");                               |
5// | you may not use this file except in compliance with the License.                              |
6// | You may obtain a copy of the License at                                                       |
7// |                                                                                               |
8// |  http://www.apache.org/licenses/LICENSE-2.0                                                   |
9// |                                                                                               |
10// | Unless required by applicable law or agreed to in writing, software                           |
11// | distributed under the License is distributed on an "AS IS" BASIS,                             |
12// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.                      |
13// | See the License for the specific language governing permissions and                           |
14// | limitations under the License.                                                                |
15// +-----------------------------------------------------------------------------------------------+
16
17use std::fmt;
18
19/// Parser error messages.
20#[derive(Clone,Copy,PartialEq)]
21pub enum ParserError {
22    /// Invalid chunk extension name on byte `u8`.
23    ChunkExtensionName(u8),
24
25    /// Invalid chunk extension value on byte `u8`.
26    ChunkExtensionValue(u8),
27
28    /// Invalid chunk length on byte `u8`.
29    ChunkLength(u8),
30
31    /// Invalid CRLF sequence on byte `u8`.
32    CrlfSequence(u8),
33
34    /// Parsing has failed.
35    Dead,
36
37    /// Invalid header name on byte `u8`.
38    HeaderName(u8),
39
40    /// Invalid header value on byte `u8`.
41    HeaderValue(u8),
42
43    /// Chunk length overflow.
44    ChunkLengthOverflow,
45
46    /// Invalid request method on byte `u8`.
47    Method(u8),
48
49    /// Invalid multipart data.
50    Multipart(u8),
51
52    /// Invalid multipart boundary.
53    MultipartBoundary(u8),
54
55    /// Invalid status on byte `u8`.
56    Status(u8),
57
58    /// Invalid status code on byte `u8`.
59    StatusCode(u8),
60
61    /// Invalid URL character on byte `u8`.
62    Url(u8),
63
64    /// Invalid URL encoded name on byte `u8`.
65    UrlEncodedName(u8),
66
67    /// Invalid URL encoded value on byte `u8`.
68    UrlEncodedValue(u8),
69
70    /// Invalid HTTP version on byte `u8`.
71    Version(u8),
72}
73
74impl ParserError {
75    /// Format this for debug and display purposes.
76    fn format(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
77        match *self {
78            ParserError::ChunkExtensionName(byte) => {
79                write!(
80                    formatter,
81                    "<ParserError::ChunkExtensionName: {}>",
82                    byte
83                )
84            },
85            ParserError::ChunkExtensionValue(byte) => {
86                write!(
87                    formatter,
88                    "<ParserError::ChunkExtensionValue: {}>",
89                    byte
90                )
91            },
92            ParserError::ChunkLength(byte) => {
93                write!(
94                    formatter,
95                    "<ParserError::ChunkLength: {}>",
96                    byte
97                )
98            },
99            ParserError::ChunkLengthOverflow => {
100                write!(
101                    formatter,
102                    "<ParserError::ChunkLengthOverflow>"
103                )
104            },
105            ParserError::CrlfSequence(byte) => {
106                write!(
107                    formatter,
108                    "<ParserError::CrlfSequence: {}>",
109                    byte
110                )
111            },
112            ParserError::Dead => {
113                write!(
114                    formatter,
115                    "<ParserError::Dead>"
116                )
117            },
118            ParserError::HeaderName(byte) => {
119                write!(
120                    formatter,
121                    "<ParserError::HeaderName: {}>",
122                    byte
123                )
124            },
125            ParserError::HeaderValue(byte) => {
126                write!(
127                    formatter,
128                    "<ParserError::HeaderValue: {}>",
129                    byte
130                )
131            },
132            ParserError::Method(byte) => {
133                write!(
134                    formatter,
135                    "<ParserError::Method: {}>",
136                    byte
137                )
138            },
139            ParserError::Multipart(byte) => {
140                write!(
141                    formatter,
142                    "<ParserError::Multipart: {}>",
143                    byte
144                )
145            },
146            ParserError::MultipartBoundary(byte) => {
147                write!(
148                    formatter,
149                    "<ParserError::MultipartBoundary: {}>",
150                    byte
151                )
152            },
153            ParserError::Status(byte) => {
154                write!(
155                    formatter,
156                    "<ParserError::Status: {}>",
157                    byte
158                )
159            },
160            ParserError::StatusCode(byte) => {
161                write!(
162                    formatter,
163                    "<ParserError::StatusCode: {}>",
164                    byte
165                )
166            },
167            ParserError::Url(byte) => {
168                write!(
169                    formatter,
170                    "<ParserError::Url: {}>",
171                    byte
172                )
173            },
174            ParserError::UrlEncodedName(byte) => {
175                write!(
176                    formatter,
177                    "<ParserError::UrlEncodedName: {}>",
178                    byte
179                )
180            },
181            ParserError::UrlEncodedValue(byte) => {
182                write!(
183                    formatter,
184                    "<ParserError::UrlEncodedValue: {}>",
185                    byte
186                )
187            },
188            ParserError::Version(byte) => {
189                write!(
190                    formatter,
191                    "<ParserError::Version: {}>",
192                    byte
193                )
194            }
195        }
196    }
197}
198
199impl fmt::Debug for ParserError {
200    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
201        self.format(formatter)
202    }
203}
204
205impl fmt::Display for ParserError {
206    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
207        self.format(formatter)
208    }
209}