I have this part in a method, It should return the page and headers to the web browser.
tSend is a wrapper class for a string, getSub just brings back another instance of the class, a sub component. tSend.get() is a string that is the page, tSend.getSub().get() is a string that contains the response headers for the page.
However, in firefox it is giving a Content Encoding Error
Code:
{
tSend.getSub().println("Content-Length: " + tSend.get().length() + "\r");
if (gzip) {
tSend.getSub().println("Content-Encoding: gzip\r");
}
tSend.getSub().println("\r");
if (mom.DEBUG)
System.out.println("Sending to client");
out.println(tSend.getSub().get());
if (gzip) {
byte[]bytes = tSend.get().getBytes();
GZIPOutputStream outGZIP = new GZIPOutputStream(out);
outGZIP.write(bytes, 0, bytes.length);
outGZIP.finish();
} else
out.println(tSend.get());
}
I have Changed the class for tSend, also I have just included the class for it. The class is just to kind of buffer the response so I could use the content length to allow me to do keep-alive in my http server.
Code:
public static class ToSend
{
private String string = "";
private ToSend sub;
public void setSub(ToSend nextLevel)
{
sub = nextLevel;
}
public ToSend getSub()
{
return sub;
}
public String get()
{
return string;
}
public void set(String s)
{
string = s;
}
public void print(String s)
{
string = string + s;
}
public void println(String s)
{
print(s + "\n");
}
}
I’m confused why you call
tSend.getSub().addln()andtSend.getSub().println()for tasks that feel identical to me.I don’t think you should send the
Content-Length:header if you compress the content — you won’t know the size until after the compression is finished.You send content down
out.println()before you’ve attached the gzip encoder to it — is this intentional? You also forget the CR\ron that line — is that intentional?Does
tSend.get()create any side-effects that make debugging this code difficult? DoestSend.getSub()or any methods called on it have any side-effects that complicate debugging?