@rip-lang/server 1.3.6 → 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/api.rip +21 -2
  2. package/package.json +1 -1
package/api.rip CHANGED
@@ -156,9 +156,9 @@ createContext = (req, params = {}) ->
156
156
  file = Bun.file(path)
157
157
  etag = "W/\"#{file.lastModified}-#{file.size}\""
158
158
  if req.headers.get('if-none-match') is etag
159
- return new Response(null, { status: 304, headers: { 'ETag': etag, 'Cache-Control': 'no-cache' } })
159
+ return new Response(null, { status: 304, headers: { 'ETag': etag, 'Cache-Control': out.get('Cache-Control') or 'no-cache' } })
160
160
  out.set 'Content-Type', (type or mimeType(path))
161
- out.set 'Cache-Control', 'no-cache'
161
+ out.set 'Cache-Control', 'no-cache' unless out.has 'Cache-Control'
162
162
  out.set 'ETag', etag
163
163
  new Response file, { status: 200, headers: out }
164
164
 
@@ -168,6 +168,25 @@ createContext = (req, params = {}) ->
168
168
  return
169
169
  out.get(name)
170
170
 
171
+ cache: (duration) ->
172
+ seconds = if typeof duration is 'number' then duration
173
+ else if typeof duration is 'string'
174
+ parts = duration.match(/^(\d+)\s*(s|sec|second|seconds|m|min|minute|minutes|h|hr|hour|hours|d|day|days|w|week|weeks|y|year|years)$/i)
175
+ if parts
176
+ n = parseInt(parts[1])
177
+ switch parts[2][0].toLowerCase()
178
+ when 's' then n
179
+ when 'm' then n * 60
180
+ when 'h' then n * 3600
181
+ when 'd' then n * 86400
182
+ when 'w' then n * 604800
183
+ when 'y' then n * 31536000
184
+ else n
185
+ else parseInt(duration) or 0
186
+ else 0
187
+ out.set 'Cache-Control', "public, max-age=#{seconds}, immutable"
188
+ return
189
+
171
190
  session: {}
172
191
 
173
192
  req:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rip-lang/server",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "Pure Rip web framework and application server",
5
5
  "type": "module",
6
6
  "main": "api.rip",