mirror of
https://github.com/vee1e/mitmproxy.git
synced 2026-09-01 18:27:18 +00:00
upload<->share,multipart.py optimised
This commit is contained in:
parent
c9bbce088e
commit
8a48cea502
3 changed files with 8 additions and 15 deletions
|
|
@ -20,7 +20,7 @@ from mitmproxy.addons import stickycookie
|
|||
from mitmproxy.addons import streambodies
|
||||
from mitmproxy.addons import save
|
||||
from mitmproxy.addons import upstream_auth
|
||||
from mitmproxy.addons import upload
|
||||
from mitmproxy.addons import share
|
||||
|
||||
|
||||
def default_addons():
|
||||
|
|
@ -47,5 +47,5 @@ def default_addons():
|
|||
streambodies.StreamBodies(),
|
||||
save.Save(),
|
||||
upstream_auth.UpstreamAuth(),
|
||||
upload.Upload()
|
||||
share.Share()
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
from urllib.request import Request, urlopen
|
||||
from urllib.error import HTTPError, URLError
|
||||
import mimetypes
|
||||
|
||||
|
||||
def get_content_type(filename):
|
||||
return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
|
||||
|
||||
|
||||
def encode_multipart_formdata(filename, content):
|
||||
|
|
@ -19,7 +14,7 @@ def encode_multipart_formdata(filename, content):
|
|||
L.append(value.encode("utf-8"))
|
||||
L.append(b'--' + LIMIT)
|
||||
L.append(b'Content-Disposition: form-data; name="file"; filename="%b"' % filename.encode("utf-8"))
|
||||
L.append(b'Content-Type: %b' % get_content_type(filename).encode("utf-8"))
|
||||
L.append(b'Content-Type: application/octet-stream')
|
||||
L.append(b'')
|
||||
L.append(content)
|
||||
L.append(b'--' + LIMIT + b'--')
|
||||
|
|
@ -28,9 +23,10 @@ def encode_multipart_formdata(filename, content):
|
|||
content_type = b'multipart/form-data; boundary=%b' % LIMIT
|
||||
return content_type, body
|
||||
|
||||
|
||||
def post_multipart(host, filename, content):
|
||||
content_type, body = encode_multipart_formdata(filename, content)
|
||||
req = Request("http://upload.share.mitmproxy.org.s3.amazonaws.com", data=body, method='POST')
|
||||
req = Request(host, data=body, method='POST')
|
||||
req.add_header('content-type', content_type)
|
||||
req.add_header('content-length', str(len(body)))
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@ import typing
|
|||
import random
|
||||
import datetime
|
||||
import time
|
||||
from urllib.request import Request, urlopen
|
||||
from urllib.error import HTTPError, URLError
|
||||
import mimetypes
|
||||
|
||||
from mitmproxy import command
|
||||
from mitmproxy import exceptions
|
||||
|
|
@ -19,7 +16,7 @@ import mitmproxy.types
|
|||
from mitmproxy.addons import multipart
|
||||
|
||||
|
||||
class Upload:
|
||||
class Share:
|
||||
def __init__(self):
|
||||
self.stream = None
|
||||
self.filt = None
|
||||
|
|
@ -70,8 +67,8 @@ class Upload:
|
|||
|
||||
return encoded
|
||||
|
||||
@command.command("upload.file")
|
||||
def upload(self, flows: typing.Sequence[flow.Flow]) -> None:
|
||||
@command.command("share.file")
|
||||
def share(self, flows: typing.Sequence[flow.Flow]) -> None:
|
||||
|
||||
d = datetime.datetime.utcnow()
|
||||
id = self.base36encode(int(time.mktime(d.timetuple()) * 1000 * random.random()))[0:7]
|
||||
Loading…
Add table
Add a link
Reference in a new issue