11package ls .ni .networkfilter .common .filter .types ;
22
3- import jakarta . validation . constraints . NotBlank ;
3+ import kong . unirest . core . HttpRequestWithBody ;
44import kong .unirest .core .HttpResponse ;
55import kong .unirest .core .JsonNode ;
66import kong .unirest .core .Unirest ;
1010import ls .ni .networkfilter .common .filter .FilterResult ;
1111import ls .ni .networkfilter .common .filter .FilterService ;
1212import org .jetbrains .annotations .NotNull ;
13+ import org .jetbrains .annotations .Nullable ;
1314
1415import java .util .List ;
1516import java .util .Optional ;
1617
1718public class NetworkFilterFilterService implements FilterService {
1819
19- @ NotNull
20+ @ Nullable
2021 private final String apiKey ;
2122
22- public NetworkFilterFilterService (@ NotNull @ NotBlank String apiKey ) {
23- this .apiKey = apiKey ;
23+ public NetworkFilterFilterService (@ Nullable String apiKey ) {
24+ this .apiKey = apiKey != null && ! apiKey . isBlank () ? apiKey : null ;
2425 }
2526
2627 @ Override
@@ -30,9 +31,14 @@ public NetworkFilterFilterService(@NotNull @NotBlank String apiKey) {
3031
3132 @ Override
3233 public @ NotNull FilterResult check (@ NotNull String ip ) {
33- HttpResponse <JsonNode > response = Unirest .post ("https://nf.ni.ls/api/check" )
34- .header ("X-API-KEY" , this .apiKey )
35- .header ("Content-Type" , "application/x-www-form-urlencoded" )
34+ HttpRequestWithBody request = Unirest .post ("https://nf.ni.ls/api/check" )
35+ .header ("Content-Type" , "application/x-www-form-urlencoded" );
36+
37+ if (this .apiKey != null ) {
38+ request .header ("X-API-KEY" , this .apiKey );
39+ }
40+
41+ HttpResponse <JsonNode > response = request
3642 .field ("ip" , ip )
3743 .asJson ();
3844
0 commit comments