Python, HTTPS (SSL), tlslite and metoda POST (and lots of pain)

Y

yatsek

Hi there.
Since quite long time I'm trying to achieve following things:
- for some sort of testing I need webserver with https access
- with POST method implemented

I found something which fits it in nicely written in Python, connected
my toys and... server hangs in some weird "inter-state" while serving
POST method

Below server code:

-------------------------

#!/usr/bin/python

from SocketServer import *
from BaseHTTPServer import *
from SimpleHTTPServer import *
from tlslite.api import *
import string,cgi,time
from os import curdir, sep


s = open("./server.pem").read()
x509 = X509()
x509.parse(s)
certChain = X509CertChain([x509])

s = open("./server.pem").read()
privateKey = parsePEMKey(s, private=True)

sessionCache = SessionCache()

#class MyHandler(BaseHTTPRequestHandler):
class MyHandler(SimpleHTTPRequestHandler):

def do_POST(self):
global rootnode
try:
ctype, pdict = cgi.parse_header(self.headers.getheader
('content-type'))
form = cgi.FieldStorage(fp = self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD':'POST',
'CONTENT_TYPE':self.headers
['content-type']} )


if ctype == 'multipart/form-data':

if form.has_key('postdata'):

temp_file = open(form['postdata'].filename,'wb')
buffer = form['postdata'].file.read()
temp_file.write(buffer)
temp_file.close()

self.send_response(200)
#set apriopriate header if you want send something
#self.send_header('Content-type', 'text/plain')
self.send_header('Content-type', 'text/html')
self.end_headers()

#... and send it
#self.wfile.write('OK')
self.wfile.write('<html><body>Post OK.</body></
html>')
except :
pass

class MyHTTPServer(ThreadingMixIn, TLSSocketServerMixIn, HTTPServer):
def handshake(self, tlsConnection):
try:
tlsConnection.handshakeServer(certChain=certChain,
privateKey=privateKey,
sessionCache=sessionCache)
tlsConnection.ignoreAbruptClose = True
return True
except TLSError, error:
print "Handshake failure:", str(error)
return False

httpd = MyHTTPServer(('127.0.0.1', 443), MyHandler)
#httpd = HTTPServer(('127.0.0.1', 80), MyHandler)

httpd.serve_forever()

--------------------

And page which is used to serve POST request:

<html>
<body>
<form method='POST' enctype='multipart/form-data' action='./'>

File to post: <input type=file name=postdata><br><br>
<input type=submit value=Send>
</form>
</body>
</html>

File is being nicely send to server but as I've mentioned above server
is halted in some interstate. Only after Ctrl+C terminates it
confirmation of successful transmition is showed in web browser

Choosing to use server without SSL (HTTPServer instead of
MyHTTPServer) makes everything work without glitch.

I would be happy to hear any suggestions

If somebody knows any alternative to achieve similar thing (https +
POST method on server side) it would be enough to get my tests
working.

Thx in advance

Greetz
Yatsek
 
S

Steve Holden

Hi there.
[...]

Yatsek:

You just "hijacked a thread" by writing your question as a reply to
somebody else's post. Be aware that a lot of newsreaders will show it as
a part of this other thread rather than giving if a thread of its own,
and so many people (who may have skimmed over the other thread) won't
see your post!

regards
Steve
 
S

Steve Holden

Wolfgang said:
Hi there.
[...]

Yatsek:

You just "hijacked a thread" by writing your question as a reply to
somebody else's post

did he? His mail headers show no reference to any other mail AFAICS
No, apparently my newsreader just decided to mingle several threads for
no apparent reason. Bizarrely the thread now appears on its own even
though I haven't restarted Thunderbird.

Yatsek, please accept my apologies.

regards
Steve
 
Y

yatsek

Wolfgang said:
(e-mail address removed) wrote:
Hi there.
[...]
Yatsek:
You just "hijacked a thread" by writing your question as a reply to
somebody else's post
did he? His mail headers show no reference to any other mail AFAICS

No, apparently my newsreader just decided to mingle several threads for
no apparent reason. Bizarrely the thread now appears on its own even
though I haven't restarted Thunderbird.

Yatsek, please accept my apologies.

regards
 Steve

Thx, my bad.
I was trying to correct spelling mistake by deleting older post just
after it was posted and re-posting. Sorry about that.

By the way - don't you think that Google could ad this feature (re-
editing post for some time after posting) and re-invent newsgroups
making it a lot of better tool for communication?

BR
Yatsek
 
S

Steve Holden

Wolfgang said:
@gmail.com wrote:
Hi there.
[...]
Yatsek:
You just "hijacked a thread" by writing your question as a reply to
somebody else's post
did he? His mail headers show no reference to any other mail AFAICS
No, apparently my newsreader just decided to mingle several threads for
no apparent reason. Bizarrely the thread now appears on its own even
though I haven't restarted Thunderbird.

Yatsek, please accept my apologies.

regards
Steve

Thx, my bad.
I was trying to correct spelling mistake by deleting older post just
after it was posted and re-posting. Sorry about that.

By the way - don't you think that Google could ad this feature (re-
editing post for some time after posting) and re-invent newsgroups
making it a lot of better tool for communication?
They probably could, but so far they don't even seem inclined to do much
about rampant spamming.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top