oestats-client.bbclass: switch to multipart/form-data (prepare for sending logs)
authorJeremy Laine <jeremy.laine@m4x.org>
Sun, 18 May 2008 14:42:41 +0000 (14:42 +0000)
committerJeremy Laine <jeremy.laine@m4x.org>
Sun, 18 May 2008 14:42:41 +0000 (14:42 +0000)
classes/oestats-client.bbclass

index 661ef74..a57bd92 100644 (file)
@@ -19,12 +19,30 @@ def oestats_getid(d):
        return f.read()
        
 def oestats_send(server, action, vars = {}):
-       import httplib, urllib
-
-       params = urllib.urlencode(vars)
-       headers = {"Content-type": "application/x-www-form-urlencoded"}
+       import httplib
+
+       # build body
+       output = []
+       bound = '----------ThIs_Is_tHe_bouNdaRY_$'
+       for key in vars:
+               assert vars[key]
+               output.append('--' + bound)
+               output.append('Content-Disposition: form-data; name="%s"' % key)
+               output.append('')
+               output.append(vars[key])
+       output.append('--' + bound + '--')
+       output.append('')
+       body = "\r\n".join(output)
+
+       # build headers
+       headers = {
+               "User-agent": "oestats-client/0.1",
+               "Content-type": "multipart/form-data; boundary=%s" % bound,
+               "Content-length": str(len(body))}
+
+       # send request
        conn = httplib.HTTPConnection(server)
-       conn.request("POST", action, params, headers)
+       conn.request("POST", action, body, headers)
        response = conn.getresponse()
        data = response.read()
        conn.close()
@@ -88,7 +106,7 @@ def oestats_task(server, d, task, status):
                'revision': bb.data.getVar('PR', d, True),
                'task': task,
                'status': status,
-               'time': elapsed,
+               'time': str(elapsed),
        })
 
 addhandler oestats_eventhandler