2008-11-19 08:22:15 +01:00
|
|
|
/*
|
2012-06-04 22:31:44 +02:00
|
|
|
* Copyright 2012 The Netty Project
|
2009-06-19 19:48:17 +02:00
|
|
|
*
|
2011-12-09 06:18:34 +01:00
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
2008-11-19 08:22:15 +01:00
|
|
|
*
|
2012-06-04 22:31:44 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-11-19 08:22:15 +01:00
|
|
|
*
|
2009-08-28 09:15:49 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
2011-12-09 06:18:34 +01:00
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
2009-08-28 09:15:49 +02:00
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-11-19 08:22:15 +01:00
|
|
|
*/
|
2011-12-09 04:38:59 +01:00
|
|
|
package io.netty.handler.codec.http;
|
2008-11-19 08:22:15 +01:00
|
|
|
|
2012-06-10 04:08:43 +02:00
|
|
|
import io.netty.buffer.ByteBuf;
|
2011-12-09 04:38:59 +01:00
|
|
|
import io.netty.channel.ChannelPipeline;
|
2012-05-16 16:02:06 +02:00
|
|
|
import io.netty.handler.codec.TooLongFrameException;
|
2009-06-19 17:35:19 +02:00
|
|
|
|
2008-11-19 08:22:15 +01:00
|
|
|
|
|
|
|
/**
|
2013-01-16 05:22:50 +01:00
|
|
|
* Decodes {@link ByteBuf}s into {@link HttpRequest}s and {@link HttpContent}s.
|
2009-06-19 17:35:19 +02:00
|
|
|
*
|
|
|
|
* <h3>Parameters that prevents excessive memory consumption</h3>
|
2009-06-19 18:45:30 +02:00
|
|
|
* <table border="1">
|
2009-06-19 17:35:19 +02:00
|
|
|
* <tr>
|
|
|
|
* <th>Name</th><th>Meaning</th>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td>{@code maxInitialLineLength}</td>
|
|
|
|
* <td>The maximum length of the initial line (e.g. {@code "GET / HTTP/1.0"})
|
|
|
|
* If the length of the initial line exceeds this value, a
|
|
|
|
* {@link TooLongFrameException} will be raised.</td>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td>{@code maxHeaderSize}</td>
|
|
|
|
* <td>The maximum length of all headers. If the sum of the length of each
|
|
|
|
* header exceeds this value, a {@link TooLongFrameException} will be raised.</td>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td>{@code maxChunkSize}</td>
|
|
|
|
* <td>The maximum length of the content or each chunk. If the content length
|
|
|
|
* exceeds this value, the transfer encoding of the decoded request will be
|
|
|
|
* converted to 'chunked' and the content will be split into multiple
|
2013-01-14 16:52:30 +01:00
|
|
|
* {@link HttpContent}s. If the transfer encoding of the HTTP request is
|
2009-06-19 17:35:19 +02:00
|
|
|
* 'chunked' already, each chunk will be split into smaller chunks if the
|
|
|
|
* length of the chunk exceeds this value. If you prefer not to handle
|
2013-01-14 16:52:30 +01:00
|
|
|
* {@link HttpContent}s in your handler, insert {@link HttpObjectAggregator}
|
2009-06-19 17:35:19 +02:00
|
|
|
* after this decoder in the {@link ChannelPipeline}.</td>
|
|
|
|
* </tr>
|
|
|
|
* </table>
|
2008-11-19 08:22:15 +01:00
|
|
|
*/
|
2013-01-14 16:52:30 +01:00
|
|
|
public class HttpRequestDecoder extends HttpObjectDecoder {
|
2008-11-19 08:22:15 +01:00
|
|
|
|
2009-06-19 17:35:19 +02:00
|
|
|
/**
|
|
|
|
* Creates a new instance with the default
|
2010-01-27 09:13:38 +01:00
|
|
|
* {@code maxInitialLineLength (4096}}, {@code maxHeaderSize (8192)}, and
|
|
|
|
* {@code maxChunkSize (8192)}.
|
2009-06-19 17:35:19 +02:00
|
|
|
*/
|
2009-03-10 09:57:02 +01:00
|
|
|
public HttpRequestDecoder() {
|
|
|
|
}
|
|
|
|
|
2009-06-19 17:35:19 +02:00
|
|
|
/**
|
|
|
|
* Creates a new instance with the specified parameters.
|
|
|
|
*/
|
2009-03-10 08:20:27 +01:00
|
|
|
public HttpRequestDecoder(
|
|
|
|
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) {
|
2013-01-20 10:40:54 +01:00
|
|
|
super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true);
|
2009-02-12 07:09:29 +01:00
|
|
|
}
|
|
|
|
|
2008-11-19 08:22:15 +01:00
|
|
|
@Override
|
2013-01-16 05:22:50 +01:00
|
|
|
protected HttpMessage createMessage(String[] initialLine) throws Exception {
|
|
|
|
return new DefaultHttpRequest(
|
2009-03-10 08:20:27 +01:00
|
|
|
HttpVersion.valueOf(initialLine[2]), HttpMethod.valueOf(initialLine[0]), initialLine[1]);
|
2008-11-19 08:22:15 +01:00
|
|
|
}
|
2009-02-12 08:32:53 +01:00
|
|
|
|
2012-09-28 08:16:29 +02:00
|
|
|
@Override
|
2013-01-16 05:22:50 +01:00
|
|
|
protected HttpMessage createInvalidMessage() {
|
|
|
|
return new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "/bad-request");
|
2012-09-28 08:16:29 +02:00
|
|
|
}
|
|
|
|
|
2009-02-12 08:32:53 +01:00
|
|
|
@Override
|
|
|
|
protected boolean isDecodingRequest() {
|
|
|
|
return true;
|
|
|
|
}
|
2008-11-19 08:22:15 +01:00
|
|
|
}
|