Resolved issue: NETTY-247 Make HttpMessage, HttpChunk and their default implementation completely mutable
This commit is contained in:
parent
4649d57097
commit
cf5ef8cf5e
@ -26,14 +26,22 @@ import org.jboss.netty.buffer.ChannelBuffer;
|
|||||||
*/
|
*/
|
||||||
public class DefaultHttpChunk implements HttpChunk {
|
public class DefaultHttpChunk implements HttpChunk {
|
||||||
|
|
||||||
private final ChannelBuffer content;
|
private ChannelBuffer content;
|
||||||
private final boolean last;
|
private boolean last;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the specified chunk content. If an empty
|
* Creates a new instance with the specified chunk content. If an empty
|
||||||
* buffer is specified, this chunk becomes the 'end of content' marker.
|
* buffer is specified, this chunk becomes the 'end of content' marker.
|
||||||
*/
|
*/
|
||||||
public DefaultHttpChunk(ChannelBuffer content) {
|
public DefaultHttpChunk(ChannelBuffer content) {
|
||||||
|
setContent(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChannelBuffer getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(ChannelBuffer content) {
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
throw new NullPointerException("content");
|
throw new NullPointerException("content");
|
||||||
}
|
}
|
||||||
@ -41,10 +49,6 @@ public class DefaultHttpChunk implements HttpChunk {
|
|||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChannelBuffer getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLast() {
|
public boolean isLast() {
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
@ -130,4 +130,8 @@ public class DefaultHttpChunkTrailer implements HttpChunkTrailer {
|
|||||||
public ChannelBuffer getContent() {
|
public ChannelBuffer getContent() {
|
||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ChannelBuffers.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setContent(ChannelBuffer content) {
|
||||||
|
throw new IllegalStateException("read-only");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,8 @@ import org.jboss.netty.util.internal.CaseIgnoringComparator;
|
|||||||
*/
|
*/
|
||||||
public class DefaultHttpMessage implements HttpMessage {
|
public class DefaultHttpMessage implements HttpMessage {
|
||||||
|
|
||||||
private final HttpVersion version;
|
|
||||||
private final Map<String, List<String>> headers = new TreeMap<String, List<String>>(CaseIgnoringComparator.INSTANCE);
|
private final Map<String, List<String>> headers = new TreeMap<String, List<String>>(CaseIgnoringComparator.INSTANCE);
|
||||||
|
private HttpVersion version;
|
||||||
private ChannelBuffer content = ChannelBuffers.EMPTY_BUFFER;
|
private ChannelBuffer content = ChannelBuffers.EMPTY_BUFFER;
|
||||||
private boolean chunked;
|
private boolean chunked;
|
||||||
|
|
||||||
@ -46,10 +46,7 @@ public class DefaultHttpMessage implements HttpMessage {
|
|||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
*/
|
*/
|
||||||
protected DefaultHttpMessage(final HttpVersion version) {
|
protected DefaultHttpMessage(final HttpVersion version) {
|
||||||
if (version == null) {
|
setProtocolVersion(version);
|
||||||
throw new NullPointerException("version");
|
|
||||||
}
|
|
||||||
this.version = version;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addHeader(final String name, final String value) {
|
public void addHeader(final String name, final String value) {
|
||||||
@ -190,6 +187,13 @@ public class DefaultHttpMessage implements HttpMessage {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setProtocolVersion(HttpVersion version) {
|
||||||
|
if (version == null) {
|
||||||
|
throw new NullPointerException("version");
|
||||||
|
}
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
public ChannelBuffer getContent() {
|
public ChannelBuffer getContent() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ package org.jboss.netty.handler.codec.http;
|
|||||||
*/
|
*/
|
||||||
public class DefaultHttpRequest extends DefaultHttpMessage implements HttpRequest {
|
public class DefaultHttpRequest extends DefaultHttpMessage implements HttpRequest {
|
||||||
|
|
||||||
private final HttpMethod method;
|
private HttpMethod method;
|
||||||
private final String uri;
|
private String uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
@ -37,24 +37,32 @@ public class DefaultHttpRequest extends DefaultHttpMessage implements HttpReques
|
|||||||
*/
|
*/
|
||||||
public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri) {
|
public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri) {
|
||||||
super(httpVersion);
|
super(httpVersion);
|
||||||
if (method == null) {
|
setMethod(method);
|
||||||
throw new NullPointerException("method");
|
setUri(uri);
|
||||||
}
|
|
||||||
if (uri == null) {
|
|
||||||
throw new NullPointerException("uri");
|
|
||||||
}
|
|
||||||
this.method = method;
|
|
||||||
this.uri = uri;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpMethod getMethod() {
|
public HttpMethod getMethod() {
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMethod(HttpMethod method) {
|
||||||
|
if (method == null) {
|
||||||
|
throw new NullPointerException("method");
|
||||||
|
}
|
||||||
|
this.method = method;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUri() {
|
public String getUri() {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUri(String uri) {
|
||||||
|
if (uri == null) {
|
||||||
|
throw new NullPointerException("uri");
|
||||||
|
}
|
||||||
|
this.uri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getMethod().toString() + ' ' + getUri() + ' ' + getProtocolVersion().getText();
|
return getMethod().toString() + ' ' + getUri() + ' ' + getProtocolVersion().getText();
|
||||||
|
@ -24,7 +24,8 @@ package org.jboss.netty.handler.codec.http;
|
|||||||
* @version $Rev$, $Date$
|
* @version $Rev$, $Date$
|
||||||
*/
|
*/
|
||||||
public class DefaultHttpResponse extends DefaultHttpMessage implements HttpResponse {
|
public class DefaultHttpResponse extends DefaultHttpMessage implements HttpResponse {
|
||||||
private final HttpResponseStatus status;
|
|
||||||
|
private HttpResponseStatus status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
@ -34,16 +35,19 @@ public class DefaultHttpResponse extends DefaultHttpMessage implements HttpRespo
|
|||||||
*/
|
*/
|
||||||
public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status) {
|
public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status) {
|
||||||
super(version);
|
super(version);
|
||||||
if (status == null) {
|
setStatus(status);
|
||||||
throw new NullPointerException("status");
|
|
||||||
}
|
|
||||||
this.status = status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponseStatus getStatus() {
|
public HttpResponseStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStatus(HttpResponseStatus status) {
|
||||||
|
if (status == null) {
|
||||||
|
throw new NullPointerException("status");
|
||||||
|
}
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -47,6 +47,10 @@ public interface HttpChunk {
|
|||||||
return ChannelBuffers.EMPTY_BUFFER;
|
return ChannelBuffers.EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setContent(ChannelBuffer content) {
|
||||||
|
throw new IllegalStateException("read-only");
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isLast() {
|
public boolean isLast() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -99,4 +103,10 @@ public interface HttpChunk {
|
|||||||
* marker, {@link ChannelBuffers#EMPTY_BUFFER} will be returned.
|
* marker, {@link ChannelBuffers#EMPTY_BUFFER} will be returned.
|
||||||
*/
|
*/
|
||||||
ChannelBuffer getContent();
|
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);
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,11 @@ public interface HttpMessage {
|
|||||||
*/
|
*/
|
||||||
HttpVersion getProtocolVersion();
|
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
|
* Returns the content of this message. If there is no content or
|
||||||
* {@link #isChunked()} returns {@code true}, an
|
* {@link #isChunked()} returns {@code true}, an
|
||||||
|
@ -41,8 +41,18 @@ public interface HttpRequest extends HttpMessage {
|
|||||||
*/
|
*/
|
||||||
HttpMethod getMethod();
|
HttpMethod getMethod();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the method of this request.
|
||||||
|
*/
|
||||||
|
void setMethod(HttpMethod method);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the URI (or path) of this request.
|
* Returns the URI (or path) of this request.
|
||||||
*/
|
*/
|
||||||
String getUri();
|
String getUri();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the URI (or path) of this request.
|
||||||
|
*/
|
||||||
|
void setUri(String uri);
|
||||||
}
|
}
|
||||||
|
@ -39,4 +39,9 @@ public interface HttpResponse extends HttpMessage {
|
|||||||
* Returns the status of this response.
|
* Returns the status of this response.
|
||||||
*/
|
*/
|
||||||
HttpResponseStatus getStatus();
|
HttpResponseStatus getStatus();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the status of this response.
|
||||||
|
*/
|
||||||
|
void setStatus(HttpResponseStatus status);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user