Skip to content

Commit

Permalink
Configurable HTTP OPTIONS method (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
dheeraj-p authored Sep 16, 2020
1 parent 5e8c0be commit 4ad0eb8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/in/projecteka/gateway/GatewayConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.data.util.Pair;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.reactive.ClientHttpConnector;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.server.WebFilter;
import reactor.core.publisher.Mono;
import reactor.netty.http.client.HttpClient;
import reactor.netty.resources.ConnectionProvider;

Expand Down Expand Up @@ -1125,4 +1129,16 @@ public GlobalExceptionHandler clientErrorExceptionHandler(ErrorAttributes errorA
globalExceptionHandler.setMessageWriters(serverCodecConfigurer.getWriters());
return globalExceptionHandler;
}

@Bean
@ConditionalOnProperty(value = "gateway.disableHttpOptionsMethod", havingValue = "true")
public WebFilter disableOptionsMethodFilter(){
return (exchange, chain) -> {
if(exchange.getRequest().getMethod().equals(HttpMethod.OPTIONS)) {
exchange.getResponse().setStatusCode(HttpStatus.METHOD_NOT_ALLOWED);
return Mono.empty();
}
return chain.filter(exchange);
};
}
}
1 change: 1 addition & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ identity:
userName: admin-user
password: welcome
gateway:
disableHttpOptionsMethod: true
db:
host: localhost
port: 5432
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ server:
gateway:
#Valid values are guava(for local), redis
cacheMethod: ${CACHE_METHOD:guava}
disableHttpOptionsMethod: ${HTTP_OPTIONS_DISABLED:true}
redis:
#Will not be used if cacheMethod is guava
host: ${REDIS_HOST:localhost}
Expand Down

0 comments on commit 4ad0eb8

Please sign in to comment.