Backend Development 14 min read

Non‑Intrusive HTTP Mock Platform (Hulk): Architecture, Implementation, and Deployment

Hulk is a non‑intrusive HTTP mock platform built with Django, mitmproxy, Vue, MongoDB and MySQL that lets teams mock client‑side, gateway-level and inter‑service APIs via configurable responses, without modifying production code, thereby reducing test‑data creation effort, stabilizing automation and improving overall testing efficiency.

DeWu Technology
DeWu Technology
DeWu Technology
Non‑Intrusive HTTP Mock Platform (Hulk): Architecture, Implementation, and Deployment

Testing often faces two pain points: (1) creating test data for dependent systems is time‑consuming and hard to cover edge cases; (2) automation (API, UI, event tracking) suffers from unstable services or test data, leading to high maintenance cost.

Only want to test system A but must generate data from its dependencies layer by layer.

Automation scripts break due to unstable services or data.

To solve these issues, mocking is the usual approach. Existing open‑source mock frameworks (Mockito, PowerMock, EasyMock, JMockit) are geared toward unit testing and not suitable for our integration‑testing scenario.

We built a non‑intrusive HTTP mock platform named Hulk that can mock interfaces without modifying production code. Hulk supports client‑side proxy, gateway‑level mock, and inter‑service mock, configurable response functions, and will later support filter‑based mock data.

Architecture

Based on Django + mitmproxy + Vue + MongoDB + MySQL .

The mock service is a Django application; the proxy layer extends mitmproxy to forward requests to the mock system; the front‑end configuration uses the company’s Poizon‑CLI scaffold.

Data storage uses MongoDB for JSON responses and MySQL for host‑mapping information.

Deployment uses Nginx + uWSGI + Django, supporting high concurrency. Example deployment script:

# 服务器项目地址
# shellcheck disable=SC2164
cd /home/dhk/workspace/hulk
python37 -m venv venv            # 生成虚拟环境
source venv/bin/activate          # 启动虚拟环境
python37 -m pip install --upgrade pip           # 升级pip
python37 -m pip install -r requirements.txt     # 安装依赖库
# shellcheck disable=SC2164
cd /home/dhk/workspace/hulk/hulk  # 进到uwsgi.ini目录
pid=`ps -ef | grep "uwsgi" | grep -v grep | awk '{print $2}' | awk 'NR==1{print}'`
if [ -n "$pid" ]
then
    uwsgi --reload uwsgi.pid
else
    uwsgi --ini uwsgi.ini
fi

Performance on a 4C8G machine meets single‑node requirements.

The mock service works like a regular business system: it receives a request, looks up configuration in MongoDB, returns the configured response, or forwards the request to the real service based on MySQL host mapping.

Key Django URL configuration:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('hulk/attention', view_attention.attention),
    path('hulk/check', view_attention.check),
    path('hulk/query_url_info', view_web.query_url_info),
    path('hulk/insert_url_info', view_web.insert_url_info),
    path('hulk/update_is_del_1', view_web.update_is_del_1),
    path('hulk/update_url_info_doc', view_web.update_url_info_doc),
    path('hulk/update_is_open', view_web.update_is_open),
    path('hulk/proxy_query_url_info', view_proxy.proxy_query_url_info),
    url(r'^(.*)$', view_mock.mock)
]

Core mock logic (simplified):

logger = logging.getLogger('log')
def mock(request, interface):
    logger.info(request.body)
    path = request.path
    data = MockApiInfo().query_url_info(path)
    if data:
        url_info = data[0]
        res = url_info['response']
        response = JsonResponse(process_response.handle_variate(res))
        if url_info.get('response_headers'):
            response_headers = json.loads(url_info['response_headers'])
            for k, v in response_headers.items():
                response.__setitem__(k, v)
        return response
    else:
        config = MockTransConfig().query_config(path)
        headers = request.headers
        if config:
            if request.method == 'POST':
                host = request.scheme + '://' + config[0]['host'] + path
                headers['Content-Type'] = 'application/json'
                res = requests.request(request.method, url=host, headers=headers, data=request.body)
                return JsonResponse(res.json())
            elif request.method == 'GET':
                host = request.scheme + '://' + config[0]['host'] + request.get_full_path_info()
                res = requests.request(request.method, url=host, headers=request.headers)
                return JsonResponse(res.json())
        else:
            return JsonResponse({"code":1001,"status":200,"msg":"请先配置接口或者开启,当前接口路径:" + path},
                                content_type="application/json; charset=utf-8")

The proxy layer (mitmproxy) decides whether a request should be mocked and redirects it accordingly:

# 是否走mock逻辑
if hulk_api.proxy_query_url_info(path.decode("utf-8")) > 0:
    print(('命中mock,接口:' + str(path)).center(100, '='))
    host = config.HULK_HOST
    scheme = b'http'
    port = 80
    headers.__delitem__('Host')
    headers.insert(0, b'Host', bytes(host))

The configuration UI lets users add mock interfaces, define custom response bodies and headers (JSON format), and validate configurations with tools like Postman.

Overall, the platform improves testing efficiency for both backend and frontend teams by providing a flexible, non‑intrusive mock solution that can be toggled on/off without code changes.

BackendtestingDeploymentmockingDjangoHTTPmitmproxy
DeWu Technology
Written by

DeWu Technology

A platform for sharing and discussing tech knowledge, guiding you toward the cloud of technology.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.