1 /*
2 * Copyright 2009 Red Hat, Inc.
3 *
4 * Red Hat licenses this file to you under the Apache License, version 2.0
5 * (the "License"); you may not use this file except in compliance with the
6 * License. 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package org.jboss.netty.handler.codec.http;
17
18 import org.jboss.netty.buffer.ChannelBuffer;
19 import org.jboss.netty.channel.ChannelPipeline;
20 import org.jboss.netty.handler.codec.frame.TooLongFrameException;
21
22
23 /**
24 * Decodes {@link ChannelBuffer}s into {@link HttpRequest}s and {@link HttpChunk}s.
25 *
26 * <h3>Parameters that prevents excessive memory consumption</h3>
27 * <table border="1">
28 * <tr>
29 * <th>Name</th><th>Meaning</th>
30 * </tr>
31 * <tr>
32 * <td>{@code maxInitialLineLength}</td>
33 * <td>The maximum length of the initial line (e.g. {@code "GET / HTTP/1.0"})
34 * If the length of the initial line exceeds this value, a
35 * {@link TooLongFrameException} will be raised.</td>
36 * </tr>
37 * <tr>
38 * <td>{@code maxHeaderSize}</td>
39 * <td>The maximum length of all headers. If the sum of the length of each
40 * header exceeds this value, a {@link TooLongFrameException} will be raised.</td>
41 * </tr>
42 * <tr>
43 * <td>{@code maxChunkSize}</td>
44 * <td>The maximum length of the content or each chunk. If the content length
45 * exceeds this value, the transfer encoding of the decoded request will be
46 * converted to 'chunked' and the content will be split into multiple
47 * {@link HttpChunk}s. If the transfer encoding of the HTTP request is
48 * 'chunked' already, each chunk will be split into smaller chunks if the
49 * length of the chunk exceeds this value. If you prefer not to handle
50 * {@link HttpChunk}s in your handler, insert {@link HttpChunkAggregator}
51 * after this decoder in the {@link ChannelPipeline}.</td>
52 * </tr>
53 * </table>
54 *
55 * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
56 * @author Andy Taylor (andy.taylor@jboss.org)
57 * @author <a href="http://gleamynode.net/">Trustin Lee</a>
58 * @version $Rev: 2095 $, $Date: 2010-01-27 17:13:38 +0900 (Wed, 27 Jan 2010) $
59 */
60 public class HttpRequestDecoder extends HttpMessageDecoder {
61
62 /**
63 * Creates a new instance with the default
64 * {@code maxInitialLineLength (4096}}, {@code maxHeaderSize (8192)}, and
65 * {@code maxChunkSize (8192)}.
66 */
67 public HttpRequestDecoder() {
68 super();
69 }
70
71 /**
72 * Creates a new instance with the specified parameters.
73 */
74 public HttpRequestDecoder(
75 int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) {
76 super(maxInitialLineLength, maxHeaderSize, maxChunkSize);
77 }
78
79 @Override
80 protected HttpMessage createMessage(String[] initialLine) throws Exception{
81 return new DefaultHttpRequest(
82 HttpVersion.valueOf(initialLine[2]), HttpMethod.valueOf(initialLine[0]), initialLine[1]);
83 }
84
85 @Override
86 protected boolean isDecodingRequest() {
87 return true;
88 }
89 }