Search in sources :

Example 1 with HeaderFields

use of com.yahoo.jdisc.HeaderFields in project vespa by vespa-engine.

the class AccessControlRequestFilterTest method allowed_request_origin_yields_allow_origin_header_in_response.

@Test
public void allowed_request_origin_yields_allow_origin_header_in_response() {
    final String ALLOWED_ORIGIN = "http://allowed.origin";
    HeaderFields headers = doFilterRequest(newRequestFilter(ALLOWED_ORIGIN), ALLOWED_ORIGIN);
    assertEquals(ALLOWED_ORIGIN, headers.getFirst(ALLOW_ORIGIN_HEADER));
}
Also used : HeaderFields(com.yahoo.jdisc.HeaderFields) Test(org.junit.Test)

Example 2 with HeaderFields

use of com.yahoo.jdisc.HeaderFields in project vespa by vespa-engine.

the class FeedHandlerTest method testResponseIsSentAfterWaitForRequestReceivedReturns.

/**
 * nginx require that a post is finished before the server ack with a response. This behaviour is verified
 * in this test
 */
@Test
public void testResponseIsSentAfterWaitForRequestReceivedReturns() throws Exception {
    HttpRequest request = mock(HttpRequest.class);
    // Create a request with valid version.
    com.yahoo.jdisc.http.HttpRequest jdiscRequest = mock(com.yahoo.jdisc.http.HttpRequest.class);
    HeaderFields headerFields = mock(HeaderFields.class);
    List<String> version = new ArrayList<>();
    version.add("2");
    when(headerFields.get(Headers.VERSION)).thenReturn(version);
    when(jdiscRequest.headers()).thenReturn(headerFields);
    when(request.getJDiscRequest()).thenReturn(jdiscRequest);
    TestFeedHandler feedHandler = new TestFeedHandler();
    // After a short period, make the feed finish.
    new Thread(() -> {
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        feedHandler.countDownLatch.countDown();
    }).start();
    // This should not return before countdown latch is stepped down.
    feedHandler.handle(request);
    // This should always returns after the countDownLatch has become zero. This might cause false positive,
    // but not false negatives. This is fine.
    assertThat(feedHandler.countDownLatch.getCount(), is(0L));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) HeaderFields(com.yahoo.jdisc.HeaderFields) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with HeaderFields

use of com.yahoo.jdisc.HeaderFields in project vespa by vespa-engine.

the class RequestViewImplTest method header_from_the_parent_request_is_available.

@Test
public void header_from_the_parent_request_is_available() throws Exception {
    final String HEADER = "single-header";
    HeaderFields parentHeaders = new HeaderFields();
    parentHeaders.add(HEADER, "value");
    RequestView requestView = newRequestView(parentHeaders);
    assertEquals(requestView.getFirstHeader(HEADER).get(), "value");
    assertEquals(requestView.getHeaders(HEADER).size(), 1);
    assertEquals(requestView.getHeaders(HEADER).get(0), "value");
}
Also used : HeaderFields(com.yahoo.jdisc.HeaderFields) Test(org.testng.annotations.Test)

Example 4 with HeaderFields

use of com.yahoo.jdisc.HeaderFields in project vespa by vespa-engine.

the class RequestViewImplTest method multi_value_header_from_the_parent_request_is_available.

@Test
public void multi_value_header_from_the_parent_request_is_available() throws Exception {
    final String HEADER = "list-header";
    HeaderFields parentHeaders = new HeaderFields();
    parentHeaders.add(HEADER, Lists.newArrayList("one", "two"));
    RequestView requestView = newRequestView(parentHeaders);
    assertEquals(requestView.getHeaders(HEADER).size(), 2);
    assertEquals(requestView.getHeaders(HEADER).get(0), "one");
    assertEquals(requestView.getHeaders(HEADER).get(1), "two");
    assertEquals(requestView.getFirstHeader(HEADER).get(), "one");
}
Also used : HeaderFields(com.yahoo.jdisc.HeaderFields) Test(org.testng.annotations.Test)

Example 5 with HeaderFields

use of com.yahoo.jdisc.HeaderFields in project vespa by vespa-engine.

the class AccessControlRequestFilterTest method disallowed_request_origin_does_not_yield_allow_origin_header_in_response.

@Test
public void disallowed_request_origin_does_not_yield_allow_origin_header_in_response() {
    HeaderFields headers = doFilterRequest(newRequestFilter("http://allowed.origin"), "http://disallowed.origin");
    assertNull(headers.getFirst(ALLOW_ORIGIN_HEADER));
}
Also used : HeaderFields(com.yahoo.jdisc.HeaderFields) Test(org.junit.Test)

Aggregations

HeaderFields (com.yahoo.jdisc.HeaderFields)7 Test (org.junit.Test)4 Test (org.testng.annotations.Test)3 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 HttpRequest (com.yahoo.jdisc.http.HttpRequest)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1