"""
HTTP requests & responses examples
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Raw HTTP request & responses header
can help to understand HTTP protocol

:copyright: (c) 2011 by Alexandr Lispython (alex@obout.ru).
:license: BSD, see LICENSE for more details.
"""

************************************************************
SIMPLE POST REQUEST
************************************************************
----------------------------------------
Request:
----------------------------------------
POST /post HTTP/1.1
User-Agent: PycURL/7.19.5
Host: h.wrttn.me
Accept: */*
Content-Length: 94
Content-Type: application/x-www-form-urlencoded


field1=value1&field2=value2+with+blanks+and+%26+chars&field2=another+field+value&field3=value3

----------------------------------------
Response:
----------------------------------------
HTTP/1.1 201 Created
Date: Wed, 31 Aug 2011 06:44:19 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Content-Length: 600
Server: LightBeer/0.568

{"body": "field1=value1&field2=value2+with+blanks+and+%26+chars&field2=another+field+value&field3=value3", "files": {}, "request_time": 0.00038790702819824219, "url": "http://h.wrttn.me/post", "ip": "8.8.8.8", "start_time": 1314773059.404907, "args": {"field2": ["value2 with blanks and & chars", "another field value"], "field3": ["value3"], "field1": ["value1"]}, "headers": {"Content-Length": "94", "X-Scheme": "http", "Connection": "close", "Accept": "*/*", "User-Agent": "PycURL/7.19.5", "Host": "h.wrttn.me", "X-Real-Ip": "8.8.8.8", "Content-Type": "application/x-www-form-urlencoded"}}
{"body": "field1=value1&field2=value2+with+blanks+and+%26+chars&field2=another+field+value&field3=value3", "files": {}, "request_time": 0.00038790702819824219, "url": "http://h.wrttn.me/post", "ip": "8.8.8.8", "start_time": 1314773059.404907, "args": {"field2": ["value2 with blanks and & chars", "another field value"], "field3": ["value3"], "field1": ["value1"]}, "headers": {"Content-Length": "94", "X-Scheme": "http", "Connection": "close", "Accept": "*/*", "User-Agent": "PycURL/7.19.5", "Host": "h.wrttn.me", "X-Real-Ip": "8.8.8.8", "Content-Type": "application/x-www-form-urlencoded"}}debug(0): Connection #0 to host h.wrttn.me left intact



************************************************************
FILE AND VARS UPLOADING
************************************************************
Fields map
'field1' string 'this is a test using httppost & stuff'
'field2' files ['/tmp/testfile1.txt', '/tmp/testfile2.txt']
'field3'string 'this is wei\000rd, but null-bytes are okay'
'uploadfieldname1' file "/tmp/testfile3.txt" with Content-Type "text/txt"
************************************************************

----------------------------------------
Request
----------------------------------------
POST /post HTTP/1.1
User-Agent: PycURL/7.19.5
Host: h.wrttn.me
Accept: */*
Content-Length: 1059
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------19b6a135992c


HTTP/1.1 100 Continue

------------------------------19b6a135992c
Content-Disposition: form-data; name="field1"

this is a test using httppost & stuff
------------------------------19b6a135992c
Content-Disposition: form-data; name="field2"
Content-Type: multipart/mixed, boundary=----------------------------0062e1a1c828

------------------------------0062e1a1c828
Content-Disposition: attachment; filename="testfile1.txt"
Content-Type: text/plain

dfkqjweifowenfbwekjfweqefwqef3wefewefwq

------------------------------0062e1a1c828
Content-Disposition: attachment; filename="testfile2.txt"
Content-Type: text/plain


dfkqjweifowenfbwekfasdfwefqwfwefqwefqjfwq

------------------------------0062e1a1c828--
------------------------------19b6a135992c
Content-Disposition: form-data; name="field3"

this is wei rd, but null-bytes are okay
------------------------------19b6a135992c
Content-Disposition: form-data; name="uploadfieldname1"; filename="testfile3.txt"
Content-Type: text/txt

dfkqjweifowenfbwekjfwq

------------------------------19b6a135992c--

----------------------------------------
Response
----------------------------------------
HTTP/1.1 201 Created
Date: Wed, 31 Aug 2011 07:13:42 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Content-Length: 2233
Server: LightBeer/0.568

{"body": "------------------------------19b6a135992c\r\nContent-Disposition: form-data; name=\"field1\"\r\n\r\nthis is a test using httppost & stuff\r\n------------------------------19b6a135992c\r\nContent-Disposition: form-data; name=\"field2\"\r\nContent-Type: multipart/mixed, boundary=----------------------------0062e1a1c828\r\n\r\n------------------------------0062e1a1c828\r\nContent-Disposition: attachment; filename=\"testfile1.txt\"\r\nContent-Type: text/plain\r\n\r\ndfkqjweifowenfbwekjfweqefwqef3wefewefwq\n\r\n------------------------------0062e1a1c828\r\nContent-Disposition: attachment; filename=\"testfile2.txt\"\r\nContent-Type: text/plain\r\n\r\ndfkqjweifowenfbwekfasdfwefqwfwefqwefqjfwq\n\r\n------------------------------0062e1a1c828--\r\n------------------------------19b6a135992c\r\nContent-Disposition: form-data; name=\"field3\"\r\n\r\nthis is wei\u0000rd, but null-bytes are okay\r\n------------------------------19b6a135992c\r\nContent-Disposition: form-data; name=\"uploadfieldname1\"; filename=\"testfile3.txt\"\r\nContent-Type: text/txt\r\n\r\ndfkqjweifowenfbwekjfwq\n\r\n------------------------------19b6a135992c--\r\n", "files": {"uploadfieldname1": [{"body": "dfkqjweifowenfbwekjfwq\n", "content_type": "text/txt", "filename": "testfil
{"body": "------------------------------19b6a135992c\r\nContent-Disposition: form-data; name=\"field1\"\r\n\r\nthis is a test using httppost & stuff\r\n------------------------------19b6a135992c\r\nContent-Disposition: form-data; name=\"field2\"\r\nContent-Type: multipart/mixed, boundary=----------------------------0062e1a1c828\r\n\r\n------------------------------0062e1a1c828\r\nContent-Disposition: attachment; filename=\"testfile1.txt\"\r\nContent-Type: text/plain\r\n\r\ndfkqjweifowenfbwekjfweqefwqef3wefewefwq\n\r\n------------------------------0062e1a1c828\r\nContent-Disposition: attachment; filename=\"testfile2.txt\"\r\nContent-Type: text/plain\r\n\r\ndfkqjweifowenfbwekfasdfwefqwfwefqwefqjfwq\n\r\n------------------------------0062e1a1c828--\r\n------------------------------19b6a135992c\r\nContent-Disposition: form-data; name=\"field3\"\r\n\r\nthis is wei\u0000rd, but null-bytes are okay\r\n------------------------------19b6a135992c\r\nContent-Disposition: form-data; name=\"uploadfieldname1\"; filename=\"testfile3.txt\"\r\nContent-Type: text/txt\r\n\r\ndfkqjweifowenfbwekjfwq\n\r\n------------------------------19b6a135992c--\r\n", "files": {"uploadfieldname1": [{"body": "dfkqjweifowenfbwekjfwq\n", "content_type": "text/txt", "filename": "testfildebug(3): e3.txt"}]}, "request_time": 0.00054907798767089844, "url": "http://h.wrttn.me/post", "ip": "8.8.8.8", "start_time": 1314774822.802351, "args": {"field2": ["------------------------------0062e1a1c828\r\nContent-Disposition: attachment; filename=\"testfile1.txt\"\r\nContent-Type: text/plain\r\n\r\ndfkqjweifowenfbwekjfweqefwqef3wefewefwq\n\r\n------------------------------0062e1a1c828\r\nContent-Disposition: attachment; filename=\"testfile2.txt\"\r\nContent-Type: text/plain\r\n\r\ndfkqjweifowenfbwekfasdfwefqwfwefqwefqjfwq\n\r\n------------------------------0062e1a1c828--"], "field3": ["this is wei\u0000rd, but null-bytes are okay"], "field1": ["this is a test using httppost & stuff"]}, "headers": {"Content-Length": "1059", "X-Scheme": "http", "Connection": "close", "Accept": "*/*", "User-Agent": "PycURL/7.19.5", "Host": "h.wrttn.me", "X-Real-Ip": "8.8.8.8", "Content-Type": "multipart/form-data; boundary=----------------------------19b6a135992c"}}
e3.txt"}]}, "request_time": 0.00054907798767089844, "url": "http://h.wrttn.me/post", "ip": "8.8.8.8", "start_time": 1314774822.802351, "args": {"field2": ["------------------------------0062e1a1c828\r\nContent-Disposition: attachment; filename=\"testfile1.txt\"\r\nContent-Type: text/plain\r\n\r\ndfkqjweifowenfbwekjfweqefwqef3wefewefwq\n\r\n------------------------------0062e1a1c828\r\nContent-Disposition: attachment; filename=\"testfile2.txt\"\r\nContent-Type: text/plain\r\n\r\ndfkqjweifowenfbwekfasdfwefqwfwefqwefqjfwq\n\r\n------------------------------0062e1a1c828--"], "field3": ["this is wei\u0000rd, but null-bytes are okay"], "field1": ["this is a test using httppost & stuff"]}, "headers": {"Content-Length": "1059", "X-Scheme": "http", "Connection": "close", "Accept": "*/*", "User-Agent": "PycURL/7.19.5", "Host": "h.wrttn.me", "X-Real-Ip": "8.8.8.8", "Content-Type": "multipart/form-data; boundary=----------------------------19b6a135992c"}}









