Malcolm: send Content-length, killed FileContents(), url bug

This commit is contained in:
david 2001-09-25 01:17:19 +00:00
parent d403f04290
commit 05f7060bd5
3 changed files with 21 additions and 18 deletions

View File

@ -1,5 +1,8 @@
ScrollServer is Copyright (c) 2001
David C. Merrill <david@lupercalia.net>
The stylesheets are hacked versions of Norman Walsh's excellent DocBook
stylesheets.
The stylesheets are very slightly hacked versions of Norman Walsh's excellent
DocBook stylesheets.
Thanks to Malcolm Tredinnick <malcolm@commsecure.com.au> for patches.

View File

@ -2,6 +2,7 @@
import os # Import required modules
import stat
import string
import commands
import StringIO
@ -27,11 +28,6 @@ lang = locale.setlocale(locale.LC_ALL) # hard code an ISO language code here to
BaseClass = SimpleHTTPServer.SimpleHTTPRequestHandler
ScrollKeeper = scrollkeeper.ScrollKeeper()
def FileContents(filename): # Return the contents of any file
f = open(filename, "r")
text = f.read()
f.close
return text
# Kind of like make. Aging not implemented yet.
@ -164,9 +160,8 @@ class RequestHandler(BaseClass): # Intercepts the HTTP requests and serves them
fileext = "jpg"
if os.path.isfile(filename + ".gif"):
fileext = "gif"
else:
fileext = ""
filename += "." + fileext
if fileext:
filename += "." + fileext
# Determine mimetype from extension
if fileext == "html" or fileext == "htm":
@ -184,19 +179,20 @@ class RequestHandler(BaseClass): # Intercepts the HTTP requests and serves them
# Send file if found, or error message
if os.path.isfile(filename):
fd = open(filename, 'r')
filesize = os.fstat(fd.fileno())[stat.ST_SIZE]
self.send_response(200)
self.send_header("Content-type", mimetype)
self.send_header("Content-length", filesize)
self.end_headers()
text = FileContents(filename)
else:
text = "Unrecognized file: " + filename
return StringIO.StringIO(text)
return fd
return self.send_Text("Unrecognized file: " + filename
# Send a text message
def send_Text(self, text):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.send_header("Content-type", "text/plain")
self.send_header("Content-length", len(text))
self.end_headers()
return StringIO.StringIO(text)
@ -206,5 +202,7 @@ def ScrollServer(): # Initialize the server
print "ScrollServer v0.6 -- development version!"
SimpleHTTPServer.test(RequestHandler)
ScrollServer()
if __name__ == '__main__':
ScrollServer()

View File

@ -15,8 +15,10 @@ class URI:
def __init__(self, uri):
self.URI = uri
temp = uri
if not uri:
return
temp = uri
temp = string.split(temp,"#")
if len(temp) > 1:
self.Anchor = temp[1]