Search in sources :

Example 1 with GENERIC_APP

use of com.hotels.styx.api.Id.GENERIC_APP in project styx by ExpediaGroup.

the class StyxBackendServiceClientTest method updatedRequestWithUpdatedHostHeaderIsPresentInResponseWhenOverrideHostHeaderIsTrue.

@Test
public void updatedRequestWithUpdatedHostHeaderIsPresentInResponseWhenOverrideHostHeaderIsTrue() {
    HttpInterceptor.Context requestContext = requestContext();
    StyxHostHttpClient hostClient = mock(StyxHostHttpClient.class);
    HttpHandler httpHandler = mock(HttpHandler.class);
    Origin origin = newOriginBuilder(updatedHostName, 9090).applicationId(GENERIC_APP).build();
    RemoteHost remoteHost = remoteHost(origin, httpHandler, hostClient);
    LoadBalancer loadBalancer = mockLoadBalancer(Optional.of(remoteHost));
    when(httpHandler.handle(any(), any())).thenReturn(Eventual.of(testResponse));
    StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).originStatsFactory(mock(OriginStatsFactory.class)).originsRestrictionCookieName("someCookie").originIdHeader("origin-id").loadBalancer(loadBalancer).retryPolicy(new RetryNTimes(0)).metrics(metrics).overrideHostHeader(true).build();
    Publisher<LiveHttpResponse> responsePublisher = styxHttpClient.sendRequest(testRequest, requestContext);
    StepVerifier.create(responsePublisher).expectNextMatches(it -> it.request().header(HttpHeaderNames.HOST).isPresent() && it.request().header(HttpHeaderNames.HOST).get().equals(updatedHostName)).verifyComplete();
}
Also used : Origin(com.hotels.styx.api.extension.Origin) RetryNTimes(com.hotels.styx.client.retry.RetryNTimes) BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) StepVerifier(reactor.test.StepVerifier) LiveHttpResponse.response(com.hotels.styx.api.LiveHttpResponse.response) Processor(org.reactivestreams.Processor) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) RemoteHost.remoteHost(com.hotels.styx.api.extension.RemoteHost.remoteHost) Support.requestContext(com.hotels.styx.support.Support.requestContext) Context(com.hotels.styx.api.HttpInterceptor.Context) Arrays.asList(java.util.Arrays.asList) Matchers.eq(org.mockito.Matchers.eq) StickySessionConfig.stickySessionDisabled(com.hotels.styx.api.extension.service.StickySessionConfig.stickySessionDisabled) LiveHttpRequest.get(com.hotels.styx.api.LiveHttpRequest.get) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) BAD_REQUEST(com.hotels.styx.api.HttpResponseStatus.BAD_REQUEST) HttpHandler(com.hotels.styx.api.HttpHandler) OriginUnreachableException(com.hotels.styx.api.exceptions.OriginUnreachableException) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) HttpHeaderNames(com.hotels.styx.api.HttpHeaderNames) LoadBalancer(com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer) Test(org.junit.jupiter.api.Test) Matchers.any(org.mockito.Matchers.any) CHUNKED(com.hotels.styx.api.HttpHeaderNames.CHUNKED) CONTENT_LENGTH(com.hotels.styx.api.HttpHeaderNames.CONTENT_LENGTH) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Mockito.inOrder(org.mockito.Mockito.inOrder) Origin(com.hotels.styx.api.extension.Origin) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) RequestCookie.requestCookie(com.hotels.styx.api.RequestCookie.requestCookie) Arrays.stream(java.util.Arrays.stream) Mockito.mock(org.mockito.Mockito.mock) RetryPolicy(com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy) GENERIC_APP(com.hotels.styx.api.Id.GENERIC_APP) StickySessionConfig(com.hotels.styx.api.extension.service.StickySessionConfig) NOT_IMPLEMENTED(com.hotels.styx.api.HttpResponseStatus.NOT_IMPLEMENTED) UNAUTHORIZED(com.hotels.styx.api.HttpResponseStatus.UNAUTHORIZED) TRANSFER_ENCODING(com.hotels.styx.api.HttpHeaderNames.TRANSFER_ENCODING) ArgumentCaptor(org.mockito.ArgumentCaptor) RetryNTimes(com.hotels.styx.client.retry.RetryNTimes) NoAvailableHostsException(com.hotels.styx.api.exceptions.NoAvailableHostsException) EmitterProcessor(reactor.core.publisher.EmitterProcessor) BackendService(com.hotels.styx.api.extension.service.BackendService) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Eventual(com.hotels.styx.api.Eventual) Matchers.empty(org.hamcrest.Matchers.empty) InOrder(org.mockito.InOrder) INTERNAL_SERVER_ERROR(com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) Publisher(org.reactivestreams.Publisher) Matchers(org.hamcrest.Matchers) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) HostAndPort(com.google.common.net.HostAndPort) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) RemoteHost(com.hotels.styx.api.extension.RemoteHost) Mockito.verify(org.mockito.Mockito.verify) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Flux(reactor.core.publisher.Flux) Mockito.never(org.mockito.Mockito.never) MeterRegistry(com.hotels.styx.api.MeterRegistry) OK(com.hotels.styx.api.HttpResponseStatus.OK) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Id(com.hotels.styx.api.Id) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) HttpHandler(com.hotels.styx.api.HttpHandler) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) LoadBalancer(com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Context(com.hotels.styx.api.HttpInterceptor.Context) RemoteHost(com.hotels.styx.api.extension.RemoteHost) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Test(org.junit.jupiter.api.Test)

Example 2 with GENERIC_APP

use of com.hotels.styx.api.Id.GENERIC_APP in project styx by ExpediaGroup.

the class StyxBackendServiceClientTest method originalRequestIsPresentInResponseWhenOverrideHostHeaderIsFalse.

@Test
public void originalRequestIsPresentInResponseWhenOverrideHostHeaderIsFalse() {
    HttpInterceptor.Context requestContext = requestContext();
    StyxHostHttpClient hostClient = mock(StyxHostHttpClient.class);
    HttpHandler httpHandler = mock(HttpHandler.class);
    Origin origin = newOriginBuilder(incomingHostname, 9090).applicationId(GENERIC_APP).build();
    RemoteHost remoteHost = remoteHost(origin, httpHandler, hostClient);
    LoadBalancer loadBalancer = mockLoadBalancer(Optional.of(remoteHost));
    when(httpHandler.handle(any(), any())).thenReturn(Eventual.of(testResponse));
    StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).originStatsFactory(mock(OriginStatsFactory.class)).originsRestrictionCookieName("someCookie").originIdHeader("origin-id").loadBalancer(loadBalancer).retryPolicy(new RetryNTimes(0)).metrics(metrics).overrideHostHeader(false).build();
    Publisher<LiveHttpResponse> responsePublisher = styxHttpClient.sendRequest(testRequest, requestContext);
    StepVerifier.create(responsePublisher).expectNextMatches(it -> it.request().header(HttpHeaderNames.HOST).isPresent() && it.request().header(HttpHeaderNames.HOST).get().equals(incomingHostname)).verifyComplete();
}
Also used : Origin(com.hotels.styx.api.extension.Origin) RetryNTimes(com.hotels.styx.client.retry.RetryNTimes) BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) StepVerifier(reactor.test.StepVerifier) LiveHttpResponse.response(com.hotels.styx.api.LiveHttpResponse.response) Processor(org.reactivestreams.Processor) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) RemoteHost.remoteHost(com.hotels.styx.api.extension.RemoteHost.remoteHost) Support.requestContext(com.hotels.styx.support.Support.requestContext) Context(com.hotels.styx.api.HttpInterceptor.Context) Arrays.asList(java.util.Arrays.asList) Matchers.eq(org.mockito.Matchers.eq) StickySessionConfig.stickySessionDisabled(com.hotels.styx.api.extension.service.StickySessionConfig.stickySessionDisabled) LiveHttpRequest.get(com.hotels.styx.api.LiveHttpRequest.get) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) BAD_REQUEST(com.hotels.styx.api.HttpResponseStatus.BAD_REQUEST) HttpHandler(com.hotels.styx.api.HttpHandler) OriginUnreachableException(com.hotels.styx.api.exceptions.OriginUnreachableException) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) HttpHeaderNames(com.hotels.styx.api.HttpHeaderNames) LoadBalancer(com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer) Test(org.junit.jupiter.api.Test) Matchers.any(org.mockito.Matchers.any) CHUNKED(com.hotels.styx.api.HttpHeaderNames.CHUNKED) CONTENT_LENGTH(com.hotels.styx.api.HttpHeaderNames.CONTENT_LENGTH) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Mockito.inOrder(org.mockito.Mockito.inOrder) Origin(com.hotels.styx.api.extension.Origin) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) RequestCookie.requestCookie(com.hotels.styx.api.RequestCookie.requestCookie) Arrays.stream(java.util.Arrays.stream) Mockito.mock(org.mockito.Mockito.mock) RetryPolicy(com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicy) GENERIC_APP(com.hotels.styx.api.Id.GENERIC_APP) StickySessionConfig(com.hotels.styx.api.extension.service.StickySessionConfig) NOT_IMPLEMENTED(com.hotels.styx.api.HttpResponseStatus.NOT_IMPLEMENTED) UNAUTHORIZED(com.hotels.styx.api.HttpResponseStatus.UNAUTHORIZED) TRANSFER_ENCODING(com.hotels.styx.api.HttpHeaderNames.TRANSFER_ENCODING) ArgumentCaptor(org.mockito.ArgumentCaptor) RetryNTimes(com.hotels.styx.client.retry.RetryNTimes) NoAvailableHostsException(com.hotels.styx.api.exceptions.NoAvailableHostsException) EmitterProcessor(reactor.core.publisher.EmitterProcessor) BackendService(com.hotels.styx.api.extension.service.BackendService) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Eventual(com.hotels.styx.api.Eventual) Matchers.empty(org.hamcrest.Matchers.empty) InOrder(org.mockito.InOrder) INTERNAL_SERVER_ERROR(com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) Publisher(org.reactivestreams.Publisher) Matchers(org.hamcrest.Matchers) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) HostAndPort(com.google.common.net.HostAndPort) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) RemoteHost(com.hotels.styx.api.extension.RemoteHost) Mockito.verify(org.mockito.Mockito.verify) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Flux(reactor.core.publisher.Flux) Mockito.never(org.mockito.Mockito.never) MeterRegistry(com.hotels.styx.api.MeterRegistry) OK(com.hotels.styx.api.HttpResponseStatus.OK) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Id(com.hotels.styx.api.Id) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) HttpHandler(com.hotels.styx.api.HttpHandler) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) LoadBalancer(com.hotels.styx.api.extension.loadbalancing.spi.LoadBalancer) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Context(com.hotels.styx.api.HttpInterceptor.Context) RemoteHost(com.hotels.styx.api.extension.RemoteHost) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Test(org.junit.jupiter.api.Test)

Aggregations

HostAndPort (com.google.common.net.HostAndPort)2 Eventual (com.hotels.styx.api.Eventual)2 HttpHandler (com.hotels.styx.api.HttpHandler)2 HttpHeaderNames (com.hotels.styx.api.HttpHeaderNames)2 CHUNKED (com.hotels.styx.api.HttpHeaderNames.CHUNKED)2 CONTENT_LENGTH (com.hotels.styx.api.HttpHeaderNames.CONTENT_LENGTH)2 TRANSFER_ENCODING (com.hotels.styx.api.HttpHeaderNames.TRANSFER_ENCODING)2 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)2 Context (com.hotels.styx.api.HttpInterceptor.Context)2 HttpResponseStatus (com.hotels.styx.api.HttpResponseStatus)2 BAD_REQUEST (com.hotels.styx.api.HttpResponseStatus.BAD_REQUEST)2 INTERNAL_SERVER_ERROR (com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR)2 NOT_IMPLEMENTED (com.hotels.styx.api.HttpResponseStatus.NOT_IMPLEMENTED)2 OK (com.hotels.styx.api.HttpResponseStatus.OK)2 UNAUTHORIZED (com.hotels.styx.api.HttpResponseStatus.UNAUTHORIZED)2 Id (com.hotels.styx.api.Id)2 GENERIC_APP (com.hotels.styx.api.Id.GENERIC_APP)2 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)2 LiveHttpRequest.get (com.hotels.styx.api.LiveHttpRequest.get)2 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)2