trying header for clientIp
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -3,11 +3,11 @@ package dev.mars3142.fhq.timezone_service.timezone.web.controllers;
|
||||
import dev.mars3142.fhq.timezone_service.timezone.domain.model.response.LocationResponse;
|
||||
import dev.mars3142.fhq.timezone_service.timezone.domain.model.response.TimeZoneResponse;
|
||||
import dev.mars3142.fhq.timezone_service.timezone.service.TimeZoneService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -19,8 +19,9 @@ public class TimeZoneController {
|
||||
private final TimeZoneService timeZoneService;
|
||||
|
||||
@GetMapping
|
||||
public TimeZoneResponse getTimeZone(HttpServletRequest request) {
|
||||
val ip = timeZoneService.getExternalIp(request.getRemoteAddr());
|
||||
public TimeZoneResponse getTimeZone(@RequestHeader(value = "X-Forwarded-For", defaultValue = "127.0.0.1") String data) {
|
||||
val clientIp = data.split(",")[0];
|
||||
val ip = timeZoneService.getExternalIp(clientIp);
|
||||
val timezoneInfo = timeZoneService.getTimeZoneInfoByIp(ip);
|
||||
val posix = timeZoneService.getPosixTimeZone(timezoneInfo.timezone());
|
||||
return new TimeZoneResponse(timezoneInfo.timezone(), timezoneInfo.abbreviation(), posix);
|
||||
|
Reference in New Issue
Block a user