Search in sources :

Example 1 with DefaultMutableHttpResponse

use of com.github.dreamhead.moco.model.DefaultMutableHttpResponse in project moco by dreamhead.

the class MocoHandler method doGetHttpResponse.

private DefaultMutableHttpResponse doGetHttpResponse(final HttpRequest request) {
    DefaultMutableHttpResponse httpResponse = newResponse(request, DEFAULT_STATUS);
    SessionContext context = new SessionContext(request, httpResponse);
    for (Setting setting : settings) {
        if (setting.match(request)) {
            setting.writeToResponse(context);
            return httpResponse;
        }
    }
    if (anySetting.match(request)) {
        anySetting.writeToResponse(context);
        return httpResponse;
    }
    monitor.onUnexpectedMessage(request);
    return newResponse(request, HttpResponseStatus.BAD_REQUEST.code());
}
Also used : DefaultMutableHttpResponse(com.github.dreamhead.moco.model.DefaultMutableHttpResponse) HttpResponseSetting(com.github.dreamhead.moco.HttpResponseSetting) Setting(com.github.dreamhead.moco.setting.Setting)

Example 2 with DefaultMutableHttpResponse

use of com.github.dreamhead.moco.model.DefaultMutableHttpResponse in project moco by dreamhead.

the class MocoHandler method handleRequest.

private FullHttpResponse handleRequest(final FullHttpRequest message) {
    HttpRequest request = DefaultHttpRequest.newRequest(message);
    DefaultMutableHttpResponse httpResponse = getHttpResponse(request);
    FullHttpResponse response = httpResponse.toFullResponse();
    prepareForKeepAlive(message, response);
    monitor.onMessageLeave(httpResponse);
    return response;
}
Also used : HttpRequest(com.github.dreamhead.moco.HttpRequest) DefaultHttpRequest(com.github.dreamhead.moco.model.DefaultHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultMutableHttpResponse(com.github.dreamhead.moco.model.DefaultMutableHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse)

Aggregations

DefaultMutableHttpResponse (com.github.dreamhead.moco.model.DefaultMutableHttpResponse)2 HttpRequest (com.github.dreamhead.moco.HttpRequest)1 HttpResponseSetting (com.github.dreamhead.moco.HttpResponseSetting)1 DefaultHttpRequest (com.github.dreamhead.moco.model.DefaultHttpRequest)1 Setting (com.github.dreamhead.moco.setting.Setting)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)1