Package com.github.dreamhead.moco

Examples of com.github.dreamhead.moco.HttpRequest


    public void writeToResponse(final SessionContext context) {
        Request request = context.getRequest();
        Response response = context.getResponse();

        if (HttpRequest.class.isInstance(request) && MutableHttpResponse.class.isInstance(response)) {
            HttpRequest httpRequest = HttpRequest.class.cast(request);
            MutableHttpResponse httpResponse = MutableHttpResponse.class.cast(response);
            doWriteToResponse(httpRequest, httpResponse);
        }
    }
View Full Code Here


    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        ctx.flush();
    }

    private FullHttpResponse handleRequest(FullHttpRequest message) {
        HttpRequest request = DefaultHttpRequest.newRequest(message);
        DefaultMutableHttpResponse httpResponse = getHttpResponse(request);
        FullHttpResponse response = httpResponse.toFullResponse();
        prepareForKeepAlive(message, response);
        monitor.onMessageLeave(httpResponse);
        return response;
View Full Code Here

public class HttpRequestDumper implements Dumper<Request> {
    private final Joiner.MapJoiner headerJoiner = Joiner.on(StringUtil.NEWLINE).withKeyValueSeparator(": ");

    @Override
    public String dump(Request request) {
        HttpRequest httpRequest = (HttpRequest)request;
        StringBuilder buf = new StringBuilder();
        appendRequestProtocolLine(httpRequest, buf);
        buf.append(StringUtil.NEWLINE);
        headerJoiner.appendTo(buf, httpRequest.getHeaders());

        appendContent(httpRequest, buf);
        return buf.toString();
    }
View Full Code Here

import static org.junit.Assert.assertThat;

public class HttpRequestMatcherTest {
    @Test
    public void should_be_match_if_request_is_same() {
        HttpRequest request = DefaultHttpRequest.builder()
                .withUri("/uri")
                .withVersion(HttpProtocolVersion.VERSION_1_1)
                .withMethod("POST")
                .withContent("proxy")
                .withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306"))
View Full Code Here

        assertThat(new HttpRequestFailoverMatcher(request).match(request), is(true));
    }

    @Test
    public void should_not_be_match_if_request_is_different() {
        HttpRequest request = DefaultHttpRequest.builder()
                .withUri("/uri")
                .withVersion(HttpProtocolVersion.VERSION_1_1)
                .withMethod("POST")
                .withContent("proxy")
                .withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306"))
                .build();

        HttpRequest another = DefaultHttpRequest.builder()
                .withUri("/uri")
                .withVersion(HttpProtocolVersion.VERSION_1_1)
                .withMethod("POST")
                .withContent("different")
                .withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306"))
View Full Code Here

        assertThat(new HttpRequestFailoverMatcher(request).match(another), is(false));
    }

    @Test
    public void should_not_be_match_if_uri_is_different() {
        HttpRequest request = DefaultHttpRequest.builder()
                .withUri("/uri")
                .withVersion(HttpProtocolVersion.VERSION_1_1)
                .withMethod("POST")
                .withContent("proxy")
                .withUri("/foo")
                .withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306"))
                .build();

        HttpRequest another = DefaultHttpRequest.builder()
                .withUri("/uri")
                .withVersion(HttpProtocolVersion.VERSION_1_1)
                .withMethod("POST")
                .withContent("proxy")
                .withUri("/bar")
View Full Code Here

        assertThat(new HttpRequestFailoverMatcher(request).match(another), is(false));
    }

    @Test
    public void should_be_match_if_failover_field_is_null() {
        HttpRequest request = DefaultHttpRequest.builder()
                .withUri("/uri")
                .withVersion(HttpProtocolVersion.VERSION_1_1)
                .withMethod("POST")
                .withContent("proxy")
                .withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306"))
                .build();

        HttpRequest failover = DefaultHttpRequest.builder()
                .withUri("/uri")
                .withMethod("POST")
                .withContent("proxy")
                .withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306"))
                .build();
View Full Code Here

        assertThat(new HttpRequestFailoverMatcher(failover).match(request), is(true));
    }

    @Test
    public void should_be_match_even_if_target_request_has_more_headers() {
        HttpRequest request = DefaultHttpRequest.builder()
                .withUri("/uri")
                .withVersion(HttpProtocolVersion.VERSION_1_1)
                .withMethod("POST")
                .withContent("proxy")
                .withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306"))
                .build();

        HttpRequest failover = DefaultHttpRequest.builder()
                .withUri("/uri")
                .withVersion(HttpProtocolVersion.VERSION_1_1)
                .withMethod("POST")
                .withContent("proxy")
                .withHeaders(of("Host", "localhost:12306"))
View Full Code Here

    private Predicate<Session> isForRequest(final HttpRequest dumpedRequest) {
        return new Predicate<Session>() {
            @Override
            public boolean apply(Session session) {
                HttpRequest request = session.getRequest();
                return new HttpRequestFailoverMatcher(request).match(dumpedRequest);
            }
        };
    }
View Full Code Here

TOP

Related Classes of com.github.dreamhead.moco.HttpRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.