Resolved issue: NETTY-247 Make HttpMessage, HttpChunk and their default implementation completely mutable

This commit is contained in:
Trustin Lee 2009-11-20 04:12:16 +00:00
parent 4649d57097
commit cf5ef8cf5e
9 changed files with 80 additions and 26 deletions

View File

@ -26,14 +26,22 @@ import org.jboss.netty.buffer.ChannelBuffer;
*/
public class DefaultHttpChunk implements HttpChunk {
private final ChannelBuffer content;
private final boolean last;
private ChannelBuffer content;
private boolean last;
/**
* Creates a new instance with the specified chunk content. If an empty
* buffer is specified, this chunk becomes the 'end of content' marker.
*/
public DefaultHttpChunk(ChannelBuffer content) {
setContent(content);
}
public ChannelBuffer getContent() {
return content;
}
public void setContent(ChannelBuffer content) {
if (content == null) {
throw new NullPointerException("content");
}
@ -41,10 +49,6 @@ public class DefaultHttpChunk implements HttpChunk {
this.content = content;
}
public ChannelBuffer getContent() {
return content;
}
public boolean isLast() {
return last;
}

View File

@ -130,4 +130,8 @@ public class DefaultHttpChunkTrailer implements HttpChunkTrailer {
public ChannelBuffer getContent() {
return ChannelBuffers.EMPTY_BUFFER;
}
public void setContent(ChannelBuffer content) {
throw new IllegalStateException("read-only");
}
}

View File

@ -37,8 +37,8 @@ import org.jboss.netty.util.internal.CaseIgnoringComparator;
*/
public class DefaultHttpMessage implements HttpMessage {
private final HttpVersion version;
private final Map<String, List<String>> headers = new TreeMap<String, List<String>>(CaseIgnoringComparator.INSTANCE);
private HttpVersion version;
private ChannelBuffer content = ChannelBuffers.EMPTY_BUFFER;
private boolean chunked;
@ -46,10 +46,7 @@ public class DefaultHttpMessage implements HttpMessage {
* Creates a new instance.
*/
protected DefaultHttpMessage(final HttpVersion version) {
if (version == null) {
throw new NullPointerException("version");
}
this.version = version;
setProtocolVersion(version);
}
public void addHeader(final String name, final String value) {
@ -190,6 +187,13 @@ public class DefaultHttpMessage implements HttpMessage {
return version;
}
public void setProtocolVersion(HttpVersion version) {
if (version == null) {
throw new NullPointerException("version");
}
this.version = version;
}
public ChannelBuffer getContent() {
return content;
}

View File

@ -25,8 +25,8 @@ package org.jboss.netty.handler.codec.http;
*/
public class DefaultHttpRequest extends DefaultHttpMessage implements HttpRequest {
private final HttpMethod method;
private final String uri;
private HttpMethod method;
private String uri;
/**
* Creates a new instance.
@ -37,24 +37,32 @@ public class DefaultHttpRequest extends DefaultHttpMessage implements HttpReques
*/
public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri) {
super(httpVersion);
if (method == null) {
throw new NullPointerException("method");
}
if (uri == null) {
throw new NullPointerException("uri");
}
this.method = method;
this.uri = uri;
setMethod(method);
setUri(uri);
}
public HttpMethod getMethod() {
return method;
}
public void setMethod(HttpMethod method) {
if (method == null) {
throw new NullPointerException("method");
}
this.method = method;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
if (uri == null) {
throw new NullPointerException("uri");
}
this.uri = uri;
}
@Override
public String toString() {
return getMethod().toString() + ' ' + getUri() + ' ' + getProtocolVersion().getText();

View File

@ -24,7 +24,8 @@ package org.jboss.netty.handler.codec.http;
* @version $Rev$, $Date$
*/
public class DefaultHttpResponse extends DefaultHttpMessage implements HttpResponse {
private final HttpResponseStatus status;
private HttpResponseStatus status;
/**
* Creates a new instance.
@ -34,16 +35,19 @@ public class DefaultHttpResponse extends DefaultHttpMessage implements HttpRespo
*/
public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status) {
super(version);
if (status == null) {
throw new NullPointerException("status");
}
this.status = status;
setStatus(status);
}
public HttpResponseStatus getStatus() {
return status;
}
public void setStatus(HttpResponseStatus status) {
if (status == null) {
throw new NullPointerException("status");
}
this.status = status;
}
@Override
public String toString() {

View File

@ -47,6 +47,10 @@ public interface HttpChunk {
return ChannelBuffers.EMPTY_BUFFER;
}
public void setContent(ChannelBuffer content) {
throw new IllegalStateException("read-only");
}
public boolean isLast() {
return true;
}
@ -99,4 +103,10 @@ public interface HttpChunk {
* marker, {@link ChannelBuffers#EMPTY_BUFFER} will be returned.
*/
ChannelBuffer getContent();
/**
* Sets the content of this chunk. If an empty buffer is specified,
* this chunk becomes the 'end of content' marker.
*/
void setContent(ChannelBuffer content);
}

View File

@ -71,6 +71,11 @@ public interface HttpMessage {
*/
HttpVersion getProtocolVersion();
/**
* Sets the protocol version of this message.
*/
void setProtocolVersion(HttpVersion version);
/**
* Returns the content of this message. If there is no content or
* {@link #isChunked()} returns {@code true}, an

View File

@ -41,8 +41,18 @@ public interface HttpRequest extends HttpMessage {
*/
HttpMethod getMethod();
/**
* Sets the method of this request.
*/
void setMethod(HttpMethod method);
/**
* Returns the URI (or path) of this request.
*/
String getUri();
/**
* Sets the URI (or path) of this request.
*/
void setUri(String uri);
}

View File

@ -39,4 +39,9 @@ public interface HttpResponse extends HttpMessage {
* Returns the status of this response.
*/
HttpResponseStatus getStatus();
/**
* Sets the status of this response.
*/
void setStatus(HttpResponseStatus status);
}