summaryrefslogtreecommitdiff
path: root/indra/llcorehttp/tests/test_llcorehttp_peer.py
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcorehttp/tests/test_llcorehttp_peer.py')
-rwxr-xr-xindra/llcorehttp/tests/test_llcorehttp_peer.py130
1 files changed, 107 insertions, 23 deletions
diff --git a/indra/llcorehttp/tests/test_llcorehttp_peer.py b/indra/llcorehttp/tests/test_llcorehttp_peer.py
index 75a3c39ef2..3c3af8dc75 100755
--- a/indra/llcorehttp/tests/test_llcorehttp_peer.py
+++ b/indra/llcorehttp/tests/test_llcorehttp_peer.py
@@ -9,7 +9,7 @@
$LicenseInfo:firstyear=2008&license=viewerlgpl$
Second Life Viewer Source Code
-Copyright (C) 2012, Linden Research, Inc.
+Copyright (C) 2012-2013, Linden Research, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -35,6 +35,10 @@ import time
import select
import getopt
from threading import Thread
+try:
+ from cStringIO import StringIO
+except ImportError:
+ from StringIO import StringIO
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from SocketServer import ThreadingMixIn
@@ -47,7 +51,30 @@ from testrunner import freeport, run, debug, VERBOSE
class TestHTTPRequestHandler(BaseHTTPRequestHandler):
"""This subclass of BaseHTTPRequestHandler is to receive and echo
LLSD-flavored messages sent by the C++ LLHTTPClient.
+
+ Target URLs are fairly free-form and are assembled by
+ concatinating fragments. Currently defined fragments
+ are:
+ - '/reflect/' Request headers are bounced back to caller
+ after prefixing with 'X-Reflect-'
+ - '/fail/' Body of request can contain LLSD with
+ 'reason' string and 'status' integer
+ which will become response header.
+ - '/bug2295/' 206 response, no data in body:
+ -- '/bug2295/0/' "Content-Range: bytes 0-75/2983"
+ -- '/bug2295/1/' "Content-Range: bytes 0-75/*"
+ -- '/bug2295/2/' "Content-Range: bytes 0-75/2983",
+ "Content-Length: 0"
+ -- '/bug2295/00000018/0/' Generates PARTIAL_FILE (18) error in libcurl.
+ "Content-Range: bytes 0-75/2983",
+ "Content-Length: 76"
+ -- '/bug2295/inv_cont_range/0/' Generates HE_INVALID_CONTENT_RANGE error in llcorehttp.
+
+ Some combinations make no sense, there's no effort to protect
+ you from that.
"""
+ ignore_exceptions = (Exception,)
+
def read(self):
# The following logic is adapted from the library module
# SimpleXMLRPCServer.py.
@@ -87,42 +114,36 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self, withdata=True):
# Of course, don't attempt to read data.
- self.answer(dict(reply="success", status=200,
- reason="Your GET operation worked"))
+ try:
+ self.answer(dict(reply="success", status=200,
+ reason="Your GET operation worked"))
+ except self.ignore_exceptions, e:
+ print >> sys.stderr, "Exception during GET (ignoring): %s" % str(e)
def do_POST(self):
# Read the provided POST data.
# self.answer(self.read())
- self.answer(dict(reply="success", status=200,
- reason=self.read()))
+ try:
+ self.answer(dict(reply="success", status=200,
+ reason=self.read()))
+ except self.ignore_exceptions, e:
+ print >> sys.stderr, "Exception during POST (ignoring): %s" % str(e)
def do_PUT(self):
# Read the provided PUT data.
# self.answer(self.read())
- self.answer(dict(reply="success", status=200,
- reason=self.read()))
+ try:
+ self.answer(dict(reply="success", status=200,
+ reason=self.read()))
+ except self.ignore_exceptions, e:
+ print >> sys.stderr, "Exception during PUT (ignoring): %s" % str(e)
def answer(self, data, withdata=True):
debug("%s.answer(%s): self.path = %r", self.__class__.__name__, data, self.path)
if "/sleep/" in self.path:
time.sleep(30)
- if "fail" not in self.path:
- data = data.copy() # we're going to modify
- # Ensure there's a "reply" key in data, even if there wasn't before
- data["reply"] = data.get("reply", llsd.LLSD("success"))
- response = llsd.format_xml(data)
- debug("success: %s", response)
- self.send_response(200)
- if "/reflect/" in self.path:
- self.reflect_headers()
- self.send_header("Content-type", "application/llsd+xml")
- self.send_header("Content-Length", str(len(response)))
- self.send_header("X-LL-Special", "Mememememe");
- self.end_headers()
- if withdata:
- self.wfile.write(response)
- else: # fail requested
+ if "fail" in self.path:
status = data.get("status", 500)
# self.responses maps an int status to a (short, long) pair of
# strings. We want the longer string. That's why we pass a string
@@ -138,6 +159,57 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler):
if "/reflect/" in self.path:
self.reflect_headers()
self.end_headers()
+ elif "/bug2295/" in self.path:
+ # Test for https://jira.secondlife.com/browse/BUG-2295
+ #
+ # Client can receive a header indicating data should
+ # appear in the body without actually getting the body.
+ # Library needs to defend against this case.
+ #
+ body = None
+ if "/bug2295/0/" in self.path:
+ self.send_response(206)
+ self.send_header("Content-Range", "bytes 0-75/2983")
+ elif "/bug2295/1/" in self.path:
+ self.send_response(206)
+ self.send_header("Content-Range", "bytes 0-75/*")
+ elif "/bug2295/2/" in self.path:
+ self.send_response(206)
+ self.send_header("Content-Range", "bytes 0-75/2983")
+ self.send_header("Content-Length", "0")
+ elif "/bug2295/00000012/0/" in self.path:
+ self.send_response(206)
+ self.send_header("Content-Range", "bytes 0-75/2983")
+ self.send_header("Content-Length", "76")
+ elif "/bug2295/inv_cont_range/0/" in self.path:
+ self.send_response(206)
+ self.send_header("Content-Range", "bytes 0-75/2983")
+ body = "Some text, but not enough."
+ else:
+ # Unknown request
+ self.send_response(400)
+ if "/reflect/" in self.path:
+ self.reflect_headers()
+ self.send_header("Content-type", "text/plain")
+ self.end_headers()
+ if body:
+ self.wfile.write(body)
+ else:
+ # Normal response path
+ data = data.copy() # we're going to modify
+ # Ensure there's a "reply" key in data, even if there wasn't before
+ data["reply"] = data.get("reply", llsd.LLSD("success"))
+ response = llsd.format_xml(data)
+ debug("success: %s", response)
+ self.send_response(200)
+ if "/reflect/" in self.path:
+ self.reflect_headers()
+ self.send_header("Content-type", "application/llsd+xml")
+ self.send_header("Content-Length", str(len(response)))
+ self.send_header("X-LL-Special", "Mememememe");
+ self.end_headers()
+ if withdata:
+ self.wfile.write(response)
def reflect_headers(self):
for name in self.headers.keys():
@@ -162,6 +234,17 @@ class Server(ThreadingMixIn, HTTPServer):
# operation of freeport() absolutely depends on it being off.
allow_reuse_address = False
+ # Override of BaseServer.handle_error(). Not too interested
+ # in errors and the default handler emits a scary traceback
+ # to stderr which annoys some. Disable this override to get
+ # default behavior which *shouldn't* cause the program to return
+ # a failure status.
+ def handle_error(self, request, client_address):
+ print '-'*40
+ print 'Ignoring exception during processing of request from',
+ print client_address
+ print '-'*40
+
if __name__ == "__main__":
do_valgrind = False
path_search = False
@@ -188,3 +271,4 @@ if __name__ == "__main__":
args = ["valgrind", "--log-file=./valgrind.log"] + args
path_search = True
sys.exit(run(server=Thread(name="httpd", target=httpd.serve_forever), use_path=path_search, *args))
+