I host a webpage from home. I created my own HTTP server using Java. This is SSCCE:
if(command.startsWith("GET")) { //client is a socket on which I reply. PrintWriter pw = new PrintWriter(client.getOutputStream(), true); String commule = command.split(" "); if(commule[0].equals("GET")) { if(commule[1].contains(".")) { File file = new File(GEQO_SERVER_ROOT + commule[1].substring(1).replaceAll("%20", " ")); if(file.exists()) { OutputStream out = client.getOutputStream(); InputStream stream = new FileInputStream(file); String response = new String(); response += "HTTP/1.1 200 OK\r\n"; response += "Date: Thu, 08 Aug 2013 08:49:37 GMT\r\n"; response += "Content-Type: text/html\r\n"; response += "Content-Length: " + file.length() + "\r\n"; response += "Connection: keep-alive\r\n"; response += "\r\n"; pw.write(response); //Assume I already initialized pw as a PrintWriter pw.flush(); copy(stream, out); stream.close(); out.close(); } else { pw.write("<html><h1>The request 404ed.</h1>"); pw.write("<body>The requested URL <b>" + commule[1] + "</b> could not be found on this server.</body></html>"); pw.flush(); } } else { BufferedReader br = new BufferedReader(new FileReader(GEQO_SERVER_ROOT + commule[1].substring(1) + "main.html")); String sCurrentLine; while ((sCurrentLine = br.readLine()) != null) { pw.print(sCurrentLine); } br.close(); } } else { pw.println("Unrecognized HTTP command."); } }
This is the source of main.html:
<html>
<title>Geqo Server</title>
<body>Geqo server online and functioning!</body>
</html>
The problem is that when I try to access this page using Chrome, it displays correctly (at least when using 127.0.0.1). But when I tried to access it in Firefox at 127.0.0.1, it works, but just gives me the html source. IE also gives me the source. Can someone tell me why Firefox and IE only show the source, instead of parsing it?
I think this contains some tips (Firebug screenshot):

My source seems to be in the <pre> . I donβt know why, but is it not such a problem?
I port is redirected. Here are the guys pages: http://110.172.170.83:17416/ (Sorry, Stackoverflow does not allow numeric links.)
EDIT: I found a problem. But before I explain, thanks to Bart for SSCCE, which I used to compare with my code. This is the problem: the if on the eighth line of if(commule[1].contains(".")) code to skip most of the code here. In this corresponding else block, there is not even any command to send headers. Thanks to artbristol for pointing this out.
Thanks in advance.
Hele
source share