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));
}
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));
}
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");
}
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");
}
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));
}
Aggregations