Skip to content

Commit f962229

Browse files
authored
Add Last-Modified header for scraped responses (#44)
1 parent 9d7333c commit f962229

File tree

7 files changed

+241
-7
lines changed

7 files changed

+241
-7
lines changed

docs/openapi.json

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,36 @@
5858
"responses": {
5959
"200": {
6060
"description": "OK.",
61+
"headers": {
62+
"Date": {
63+
"description": "Date and time of when the request was processed.",
64+
"schema": {
65+
"type": "string",
66+
"example": "Thu, 01 Jan 1970 00:00:00 GMT"
67+
}
68+
},
69+
"X-Ratelimit-Limit": {
70+
"description": "Maximum number of requests per minute per IP address.",
71+
"schema": {
72+
"type": "integer",
73+
"example": 512
74+
}
75+
},
76+
"X-Ratelimit-Remaining": {
77+
"description": "Number of requests left for your IP address for the current minute.",
78+
"schema": {
79+
"type": "integer",
80+
"example": 256
81+
}
82+
},
83+
"X-Ratelimit-Reset": {
84+
"description": "Timestamp of the next minute, when rate limit resets.",
85+
"schema": {
86+
"type": "integer",
87+
"example": 1746433664
88+
}
89+
}
90+
},
6191
"content": {
6292
"application/json": {
6393
"schema": {
@@ -181,6 +211,50 @@
181211
"responses": {
182212
"200": {
183213
"description": "OK.",
214+
"headers": {
215+
"Date": {
216+
"description": "Date and time of when the request was processed.",
217+
"schema": {
218+
"type": "string",
219+
"example": "Thu, 01 Jan 1970 00:00:00 GMT"
220+
}
221+
},
222+
"Expires": {
223+
"description": "Date and time of when cache for this response will expire, and the scraper will be ready to refetch the data with the next request.",
224+
"schema": {
225+
"type": "string",
226+
"example": "Thu, 01 Jan 1970 03:00:00 GMT"
227+
}
228+
},
229+
"Last-Modified": {
230+
"description": "Date and time when the scraper fetched the data.",
231+
"schema": {
232+
"type": "string",
233+
"example": "Thu, 01 Jan 1970 00:00:00 GMT"
234+
}
235+
},
236+
"X-Ratelimit-Limit": {
237+
"description": "Maximum number of requests per minute per IP address.",
238+
"schema": {
239+
"type": "integer",
240+
"example": 512
241+
}
242+
},
243+
"X-Ratelimit-Remaining": {
244+
"description": "Number of requests left for your IP address for the current minute.",
245+
"schema": {
246+
"type": "integer",
247+
"example": 256
248+
}
249+
},
250+
"X-Ratelimit-Reset": {
251+
"description": "Timestamp of the next minute, when rate limit resets.",
252+
"schema": {
253+
"type": "integer",
254+
"example": 1746433664
255+
}
256+
}
257+
},
184258
"content": {
185259
"application/json": {
186260
"schema": {
@@ -523,6 +597,50 @@
523597
"responses": {
524598
"200": {
525599
"description": "OK.",
600+
"headers": {
601+
"Date": {
602+
"description": "Date and time of when the request was processed.",
603+
"schema": {
604+
"type": "string",
605+
"example": "Thu, 01 Jan 1970 00:00:00 GMT"
606+
}
607+
},
608+
"Expires": {
609+
"description": "Date and time of when cache for this response will expire, and the scraper will be ready to refetch the data with the next request.",
610+
"schema": {
611+
"type": "string",
612+
"example": "Thu, 01 Jan 1970 03:00:00 GMT"
613+
}
614+
},
615+
"Last-Modified": {
616+
"description": "Date and time when the scraper fetched the data.",
617+
"schema": {
618+
"type": "string",
619+
"example": "Thu, 01 Jan 1970 00:00:00 GMT"
620+
}
621+
},
622+
"X-Ratelimit-Limit": {
623+
"description": "Maximum number of requests per minute per IP address.",
624+
"schema": {
625+
"type": "integer",
626+
"example": 512
627+
}
628+
},
629+
"X-Ratelimit-Remaining": {
630+
"description": "Number of requests left for your IP address for the current minute.",
631+
"schema": {
632+
"type": "integer",
633+
"example": 256
634+
}
635+
},
636+
"X-Ratelimit-Reset": {
637+
"description": "Timestamp of the next minute, when rate limit resets.",
638+
"schema": {
639+
"type": "integer",
640+
"example": 1746433664
641+
}
642+
}
643+
},
526644
"content": {
527645
"application/json": {
528646
"schema": {
@@ -639,6 +757,50 @@
639757
"responses": {
640758
"200": {
641759
"description": "OK.",
760+
"headers": {
761+
"Date": {
762+
"description": "Date and time of when the request was processed.",
763+
"schema": {
764+
"type": "string",
765+
"example": "Thu, 01 Jan 1970 00:00:00 GMT"
766+
}
767+
},
768+
"Expires": {
769+
"description": "Date and time of when cache for this response will expire, and the scraper will be ready to refetch the data with the next request.",
770+
"schema": {
771+
"type": "string",
772+
"example": "Thu, 01 Jan 1970 03:00:00 GMT"
773+
}
774+
},
775+
"Last-Modified": {
776+
"description": "Date and time when the scraper fetched the data.",
777+
"schema": {
778+
"type": "string",
779+
"example": "Thu, 01 Jan 1970 00:00:00 GMT"
780+
}
781+
},
782+
"X-Ratelimit-Limit": {
783+
"description": "Maximum number of requests per minute per IP address.",
784+
"schema": {
785+
"type": "integer",
786+
"example": 512
787+
}
788+
},
789+
"X-Ratelimit-Remaining": {
790+
"description": "Number of requests left for your IP address for the current minute.",
791+
"schema": {
792+
"type": "integer",
793+
"example": 256
794+
}
795+
},
796+
"X-Ratelimit-Reset": {
797+
"description": "Timestamp of the next minute, when rate limit resets.",
798+
"schema": {
799+
"type": "integer",
800+
"example": 1746433664
801+
}
802+
}
803+
},
642804
"content": {
643805
"application/json": {
644806
"schema": {
@@ -747,6 +909,50 @@
747909
"responses": {
748910
"200": {
749911
"description": "OK.",
912+
"headers": {
913+
"Date": {
914+
"description": "Date and time of when the request was processed.",
915+
"schema": {
916+
"type": "string",
917+
"example": "Thu, 01 Jan 1970 00:00:00 GMT"
918+
}
919+
},
920+
"Expires": {
921+
"description": "Date and time of when cache for this response will expire, and the scraper will be ready to refetch the data with the next request.",
922+
"schema": {
923+
"type": "string",
924+
"example": "Thu, 01 Jan 1970 03:00:00 GMT"
925+
}
926+
},
927+
"Last-Modified": {
928+
"description": "Date and time when the scraper fetched the data.",
929+
"schema": {
930+
"type": "string",
931+
"example": "Thu, 01 Jan 1970 00:00:00 GMT"
932+
}
933+
},
934+
"X-Ratelimit-Limit": {
935+
"description": "Maximum number of requests per minute per IP address.",
936+
"schema": {
937+
"type": "integer",
938+
"example": 512
939+
}
940+
},
941+
"X-Ratelimit-Remaining": {
942+
"description": "Number of requests left for your IP address for the current minute.",
943+
"schema": {
944+
"type": "integer",
945+
"example": 256
946+
}
947+
},
948+
"X-Ratelimit-Reset": {
949+
"description": "Timestamp of the next minute, when rate limit resets.",
950+
"schema": {
951+
"type": "integer",
952+
"example": 1746433664
953+
}
954+
}
955+
},
750956
"content": {
751957
"application/json": {
752958
"schema": {
@@ -823,6 +1029,36 @@
8231029
"responses": {
8241030
"200": {
8251031
"description": "OK.",
1032+
"headers": {
1033+
"Date": {
1034+
"description": "Date and time of when the request was processed.",
1035+
"schema": {
1036+
"type": "string",
1037+
"example": "Thu, 01 Jan 1970 00:00:00 GMT"
1038+
}
1039+
},
1040+
"X-Ratelimit-Limit": {
1041+
"description": "Maximum number of requests per minute per IP address.",
1042+
"schema": {
1043+
"type": "integer",
1044+
"example": 512
1045+
}
1046+
},
1047+
"X-Ratelimit-Remaining": {
1048+
"description": "Number of requests left for your IP address for the current minute.",
1049+
"schema": {
1050+
"type": "integer",
1051+
"example": 256
1052+
}
1053+
},
1054+
"X-Ratelimit-Reset": {
1055+
"description": "Timestamp of the next minute, when rate limit resets.",
1056+
"schema": {
1057+
"type": "integer",
1058+
"example": 1746433664
1059+
}
1060+
}
1061+
},
8261062
"content": {
8271063
"application/json": {
8281064
"schema": {

handlers/getAdventurer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func getAdventurer(w http.ResponseWriter, r *http.Request) {
2323
}
2424

2525
if data, status, date, expires, ok := cache.Profiles.GetRecord([]string{region, profileTarget}); ok {
26-
w.Header().Set("Date", date)
2726
w.Header().Set("Expires", expires)
27+
w.Header().Set("Last-Modified", date)
2828

2929
if status == http.StatusOK {
3030
json.NewEncoder(w).Encode(data)

handlers/getAdventurerSearch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func getAdventurerSearch(w http.ResponseWriter, r *http.Request) {
2626
searchType := validators.ValidateSearchTypeQueryParam(searchTypeQueryParam)
2727

2828
if data, status, date, expires, ok := cache.ProfileSearch.GetRecord([]string{region, query, searchType}); ok {
29-
w.Header().Set("Date", date)
3029
w.Header().Set("Expires", expires)
30+
w.Header().Set("Last-Modified", date)
3131

3232
if status == http.StatusOK {
3333
json.NewEncoder(w).Encode(data)

handlers/getGuild.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func getGuild(w http.ResponseWriter, r *http.Request) {
2323
}
2424

2525
if data, status, date, expires, ok := cache.GuildProfiles.GetRecord([]string{region, name}); ok {
26-
w.Header().Set("Date", date)
2726
w.Header().Set("Expires", expires)
27+
w.Header().Set("Last-Modified", date)
2828

2929
if status == http.StatusOK {
3030
json.NewEncoder(w).Encode(data)

handlers/getGuildSearch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func getGuildSearch(w http.ResponseWriter, r *http.Request) {
2323
}
2424

2525
if data, status, date, expires, ok := cache.GuildSearch.GetRecord([]string{region, name}); ok {
26-
w.Header().Set("Date", date)
2726
w.Header().Set("Expires", expires)
27+
w.Header().Set("Last-Modified", date)
2828

2929
if status == http.StatusOK {
3030
json.NewEncoder(w).Encode(data)

handlers/getStatus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
var initTime = time.Now()
15-
var version = "1.11.1"
15+
var version = "1.11.2"
1616

1717
func getStatus(w http.ResponseWriter, r *http.Request) {
1818
json.NewEncoder(w).Encode(map[string]interface{}{

handlers/giveMaintenanceResponse.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package handlers
22

33
import (
44
"net/http"
5-
"time"
65

76
"bdo-rest-api/scraper"
87
"bdo-rest-api/utils"
@@ -15,7 +14,6 @@ func giveMaintenanceResponse(w http.ResponseWriter, region string) (ok bool) {
1514
return false
1615
}
1716

18-
w.Header().Set("Date", utils.FormatDateForHeaders(time.Now()))
1917
w.Header().Set("Expires", utils.FormatDateForHeaders(expires))
2018
w.WriteHeader(http.StatusServiceUnavailable)
2119
return true

0 commit comments

Comments
 (0)