Resolved NETTY-88 (Change the HTTP codec to use String instead of URI)

This commit is contained in:
Trustin Lee 2008-12-01 05:27:56 +00:00
parent d95f4efc4d
commit 2d92771ae6
6 changed files with 11 additions and 13 deletions

View File

@ -87,8 +87,10 @@ public class HttpClient {
} }
// Send the HTTP request. // Send the HTTP request.
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, uri); HttpRequest request = new DefaultHttpRequest(
HttpVersion.HTTP_1_0, HttpMethod.GET, uri.toASCIIString());
request.addHeader(HttpHeaders.HOST, host); request.addHeader(HttpHeaders.HOST, host);
channel.write(request); channel.write(request);
// Wait for the server to close the connection. // Wait for the server to close the connection.

View File

@ -50,7 +50,7 @@ public class HttpRequestHandler extends SimpleChannelHandler {
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
HttpRequest request = (HttpRequest) e.getMessage(); HttpRequest request = (HttpRequest) e.getMessage();
System.out.println(request.getContent().toString(Charset.defaultCharset().name())); System.out.println(request.getContent().toString(Charset.defaultCharset().name()));
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getURI()); QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri());
Map<String, List<String>> params = queryStringDecoder.getParameters(); Map<String, List<String>> params = queryStringDecoder.getParameters();
for (Entry<String, List<String>> p: params.entrySet()) { for (Entry<String, List<String>> p: params.entrySet()) {
String key = p.getKey(); String key = p.getKey();

View File

@ -21,7 +21,6 @@
*/ */
package org.jboss.netty.handler.codec.http; package org.jboss.netty.handler.codec.http;
import java.net.URI;
/** /**
* An http request implementation * An http request implementation
@ -33,10 +32,9 @@ import java.net.URI;
public class DefaultHttpRequest extends DefaultHttpMessage implements HttpRequest { public class DefaultHttpRequest extends DefaultHttpMessage implements HttpRequest {
private final HttpMethod method; private final HttpMethod method;
private final String uri;
private final URI uri; public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri) {
public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, URI uri) {
super(httpVersion); super(httpVersion);
this.method = method; this.method = method;
this.uri = uri; this.uri = uri;
@ -46,7 +44,7 @@ public class DefaultHttpRequest extends DefaultHttpMessage implements HttpReques
return method; return method;
} }
public URI getURI() { public String getUri() {
return uri; return uri;
} }
} }

View File

@ -21,7 +21,6 @@
*/ */
package org.jboss.netty.handler.codec.http; package org.jboss.netty.handler.codec.http;
import java.net.URI;
/** /**
* An http request. * An http request.
@ -33,5 +32,5 @@ public interface HttpRequest extends HttpMessage {
HttpMethod getMethod(); HttpMethod getMethod();
URI getURI(); String getUri();
} }

View File

@ -21,8 +21,6 @@
*/ */
package org.jboss.netty.handler.codec.http; package org.jboss.netty.handler.codec.http;
import java.net.URI;
import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffer;
/** /**
@ -39,7 +37,8 @@ public class HttpRequestDecoder extends HttpMessageDecoder {
String line = readIntoCurrentLine(buffer); String line = readIntoCurrentLine(buffer);
checkpoint(ResponseState.READ_HEADER); checkpoint(ResponseState.READ_HEADER);
String[] split = splitInitial(line); String[] split = splitInitial(line);
message = new DefaultHttpRequest(HttpVersion.decode(split[2]), HttpMethod.valueOf(split[0]), new URI(split[1])); message = new DefaultHttpRequest(
HttpVersion.decode(split[2]), HttpMethod.valueOf(split[0]), split[1]);
} }
} }

View File

@ -45,7 +45,7 @@ public class HttpRequestEncoder extends HttpMessageEncoder {
HttpRequest request = (HttpRequest) message; HttpRequest request = (HttpRequest) message;
buf.writeBytes(request.getMethod().getMethod().getBytes()); buf.writeBytes(request.getMethod().getMethod().getBytes());
buf.writeByte(SP); buf.writeByte(SP);
buf.writeBytes(request.getURI().toASCIIString().getBytes()); buf.writeBytes(request.getUri().getBytes());
buf.writeByte(SP); buf.writeByte(SP);
buf.writeBytes(request.getProtocolVersion().value().getBytes()); buf.writeBytes(request.getProtocolVersion().value().getBytes());
buf.writeBytes(CRLF); buf.writeBytes(CRLF);