Fix an issue caused by some editors when editing a request/response body.

Many editors make it hard save a file without a terminating newline on the last
line. When editing message bodies, this can cause problems. For now, I just
strip the newlines off the end of the body when we return from an editor.
This commit is contained in:
Aldo Cortesi 2012-01-21 12:43:00 +13:00
parent 2a09cad420
commit d5e3722c97
6 changed files with 7 additions and 11 deletions

View File

@ -454,7 +454,8 @@ class ConnectionView(WWrap):
self.flow.backup() self.flow.backup()
if part == "b": if part == "b":
conn.content = self._spawn_editor(conn.content or "") c = self._spawn_editor(conn.content or "")
conn.content = c.rstrip("\n")
elif part == "h": elif part == "h":
headertext = self._spawn_editor(repr(conn.headers)) headertext = self._spawn_editor(repr(conn.headers))
headers = flow.Headers() headers = flow.Headers()

View File

@ -122,7 +122,7 @@ def parse_request_line(request):
if major != 1: if major != 1:
raise ProxyError(400, "Unsupported protocol") raise ProxyError(400, "Unsupported protocol")
return method, scheme, host, port, path, minor return method, scheme, host, port, path, minor
class FileLike: class FileLike:
def __init__(self, o): def __init__(self, o):

View File

@ -413,7 +413,7 @@ def parse_url(url):
def parse_size(s): def parse_size(s):
""" """
Parses a size specification. Valid specifications are: Parses a size specification. Valid specifications are:
123: bytes 123: bytes
123k: kilobytes 123k: kilobytes
123m: megabytes 123m: megabytes
@ -437,6 +437,3 @@ def parse_size(s):
return int(s) * mult return int(s) * mult
except ValueError: except ValueError:
raise ValueError("Invalid size specification: %s"%s) raise ValueError("Invalid size specification: %s"%s)

View File

@ -4,7 +4,5 @@ from BaseHTTPServer import HTTPServer
import handler import handler
def make(port): def make(port):
server_address = ('', port) server_address = ('127.0.0.1', port)
return HTTPServer(server_address, handler.TestRequestHandler) return HTTPServer(server_address, handler.TestRequestHandler)

View File

@ -18,5 +18,5 @@ class SecureHTTPServer(HTTPServer):
def make(port): def make(port):
server_address = ('', port) server_address = ('127.0.0.1', port)
return SecureHTTPServer(server_address, handler.TestRequestHandler) return SecureHTTPServer(server_address, handler.TestRequestHandler)

View File

@ -41,7 +41,7 @@ class uProxy(tutils.ProxTest):
assert f.code == 200 assert f.code == 200
assert f.read() assert f.read()
f.close() f.close()
l = self.log() l = self.log()
assert l[0].address assert l[0].address
assert "host" in l[1].headers assert "host" in l[1].headers