diff options
Diffstat (limited to 'pki/base/util/src/com/netscape/cmsutil/http/HttpMessage.java')
-rw-r--r-- | pki/base/util/src/com/netscape/cmsutil/http/HttpMessage.java | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/pki/base/util/src/com/netscape/cmsutil/http/HttpMessage.java b/pki/base/util/src/com/netscape/cmsutil/http/HttpMessage.java index 93eeef68c..b0a0f0df7 100644 --- a/pki/base/util/src/com/netscape/cmsutil/http/HttpMessage.java +++ b/pki/base/util/src/com/netscape/cmsutil/http/HttpMessage.java @@ -17,21 +17,18 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmsutil.http; - import java.io.BufferedReader; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.Enumeration; import java.util.Hashtable; - /** - * Basic HTTP Message, excluding message body. - * Not optimized for performance. + * Basic HTTP Message, excluding message body. Not optimized for performance. * Set fields or parse from input. */ public class HttpMessage { - protected String mLine = null; // request or response line. + protected String mLine = null; // request or response line. protected Hashtable mHeaders = null; protected String mContent = null; // arbitrary content chars assumed. @@ -42,14 +39,14 @@ public class HttpMessage { mHeaders = new Hashtable(); } - /** + /** * Set a header field. <br> * Content-length is automatically set on write.<br> - * If value spans multiple lines must be in proper http format for - * multiple lines. + * If value spans multiple lines must be in proper http format for multiple + * lines. */ public void setHeader(String name, String value) { - if (mHeaders == null) + if (mHeaders == null) mHeaders = new Hashtable(); mHeaders.put(name.toLowerCase(), value); } @@ -62,11 +59,9 @@ public class HttpMessage { } /** - * write http headers - * does not support values of more than one line + * write http headers does not support values of more than one line */ - public void writeHeaders(OutputStreamWriter writer) - throws IOException { + public void writeHeaders(OutputStreamWriter writer) throws IOException { if (mHeaders != null) { Enumeration keys = mHeaders.keys(); String header, value; @@ -81,11 +76,10 @@ public class HttpMessage { } /** - * read http headers. - * does not support values of more than one line or multivalue headers. + * read http headers. does not support values of more than one line or + * multivalue headers. */ - public void readHeaders(BufferedReader reader) - throws IOException { + public void readHeaders(BufferedReader reader) throws IOException { mHeaders = new Hashtable(); int colon; @@ -93,7 +87,7 @@ public class HttpMessage { while (true) { line = reader.readLine(); - if (line == null || line.equals("")) + if (line == null || line.equals("")) break; colon = line.indexOf(':'); if (colon == -1) { @@ -106,8 +100,7 @@ public class HttpMessage { } } - public void write(OutputStreamWriter writer) - throws IOException { + public void write(OutputStreamWriter writer) throws IOException { writer.write(mLine + Http.CRLF); writeHeaders(writer); writer.flush(); @@ -117,13 +110,12 @@ public class HttpMessage { writer.flush(); } - public void parse(BufferedReader reader) - throws IOException { + public void parse(BufferedReader reader) throws IOException { String line = reader.readLine(); -// if (line == null) { - // throw new HttpEofException("End of stream reached"); - // } + // if (line == null) { + // throw new HttpEofException("End of stream reached"); + // } if (line.equals("")) { throw new HttpProtocolException("Bad Http req/resp line " + line); } @@ -143,7 +135,7 @@ public class HttpMessage { done = reader.read(cbuf, total, len - total); total += done; } - + mContent = new String(cbuf); } } |