测试用可编程http服务器
har-server的Python项目详细描述
简单的可编程http api服务器。
服务器可以使用HTTP Archive(har)中的元素进行编程 最初由Jan Odvarko和W3C开发的规范 网络性能工作组。它从来没有在 JanOdvarko在他的博客上维护了这个规范。我创造了 此项目在发现由Mashape创建的mockbin服务之后 (现在KongHQ)。不幸的是,mockbin不能满足我的确切需求。
用法
主要用例是将编程响应返回到指定的 请求。响应与匹配的请求一起发布到服务。 两者都被指定为har对象–请求是一个HAR request并且 响应是aHAR response
POST /responses HTTP/1.1 Host: 127.0.0.1:8080 Content-Type: application/json Content-Length: 733 { "request": { "method": "GET", "url": "http://example.org/status", "httpVersion": "HTTP/1.1", "cookies": [], "headers": [], "queryString": [], "postData": {}, "headersSize": -1, "bodySize": 0 }, "response": { "status": 200, "statusText": "OK", "httpVersion": "HTTP/1.1", "cookies": [], "headers": [ {"name":"Content-Type", "value":"application/json"} ], "content": { "mimeType": "application/json", "encoding": "json", "text": { "service": "my-service", "status": "ok" } }, "redirectURL": "", "headersSize": -1, "bodySize": -1 } } HTTP/1.1 200 OK Content-Type: application/json Content-Length: 49 Link: <http://127.0.0.1:8080/hosts>; rel=host-map; method=GET Link: <http://127.0.0.1:8080/requests>; rel=requests; method=GET Link: <http://127.0.0.1:8080/responses>; rel=add-response; method=POST Link: <http://127.0.0.1:8080/responses>; rel=clear-responses; method=PURGE { "effective_url": "http://127.0.0.1:32443" }
发送此消息后,服务将响应GET /status 在端口32443上,已注册响应:
GET /status HTTP/1.1 Host: 127.0.0.1:32443 HTTP/1.1 200 OK Content-Type: application/json { "service": "my-service", "status": "ok" }