代码拉取完成,页面将自动刷新
You can extend Moco, if you need more features than Moco already provides.
The basic idea is very simple: RequestMatcher and ResponseHandler. If your request matches any matcher, the corresponding response handler will be invoked to return response.
@Since 1.3.0
If you want to implement your own matcher, you can write with conditional
API which is supported in Java code.
server.request(conditional(request -> request.getContent().toString().equals("foo"))).response("foo");
If you want to write response based on the request, simply write a ResponseHandler
.
public interface ResponseHandler extends ConfigApplier<ResponseHandler> {
void writeToResponse(SessionContext context);
}
You just want to rewrite your own HTTP content in most cases, you can extend AbstractHttpContentResponseHandler
.
public class AbstractContentResponseHandler extends AbstractHttpContentResponseHandler {
protected MessageContent responseContent(HttpRequest httpRequest) {
return MessageContent.content("hello Moco");
}
protected abstract MediaType getContentType(HttpRequest request) {
return MediaType.PLAIN_TEXT_UTF_8;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。