rage-iodine 3.1.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef4ff042834d322d1a1eba37963ac373146345da2f167b75b421dbf6449f4060
4
- data.tar.gz: 8ca3321bfd60e376ecb10017b118295f82d1ddf9897869f84aefad13909f3dfc
3
+ metadata.gz: a1cf5cbcae299e1e28aaca04e99ea7ab9204a4d98fbf9434b27620f7588c22bc
4
+ data.tar.gz: 634a243fc8abdff8bfa59e21cf4e2a95a356e309569d17e85568cd5c2803d38f
5
5
  SHA512:
6
- metadata.gz: e55be44f50f6a779d9d1457a61dcc9c005055a52c1560dde62fb84d73226b78084a431571af0d3fb24388100236fd39dac0c624a73fab624e0529a20286d0500
7
- data.tar.gz: 74e9602b4822a05b2b25f87a0685ed8311afc79dd7e266b1e032906d18e15f0ba186870ea3617682c3939bdd2155e64759193504d8b83d4942ddabe3669c50bb
6
+ metadata.gz: e25730fe3ce0166e0e7ad4e260a1a1d15787cc264c906fce21a6a960614c3d5d033cbb597bb54cb36a97c316f8f64c5bd079e2c4d3f4cf5b6f0de1d890d92f27
7
+ data.tar.gz: fa94545855b466b9a16f00dbb267161b0cad66c546d973aa589bd74500868381c349e6d8df5d18c983fa3ecb4fd69fa5f21e57dbedc0f69c833c809c1eb4dc8f
data/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@ Please notice that this change log contains changes for upcoming releases as wel
6
6
 
7
7
  ## Changes:
8
8
 
9
+ #### Change log v.3.3.0 (2024-08-18)
10
+
11
+ **Update**: Improvements and fixes for the static file service.
12
+
13
+ #### Change log v.3.2.0 (2024-07-15)
14
+
15
+ **Update**: Explicitly undefine the alloc function on IodineObjectStorage.
16
+
9
17
  #### Change log v.3.1.0 (2024-05-01)
10
18
 
11
19
  **Update**: Implement graceful shutdown.
data/ext/iodine/http.c CHANGED
@@ -460,23 +460,16 @@ no_gzip_support:
460
460
  !(S_ISREG(file_data.st_mode) || S_ISLNK(file_data.st_mode)))
461
461
  return -1;
462
462
  found_file:
463
- /* set last-modified */
464
- {
465
- FIOBJ tmp = fiobj_str_buf(32);
466
- fiobj_str_resize(
467
- tmp, http_time2str(fiobj_obj2cstr(tmp).data, file_data.st_mtime));
468
- http_set_header(h, HTTP_HEADER_LAST_MODIFIED, tmp);
469
- }
470
463
  /* set cache-control */
471
464
  http_set_header(h, HTTP_HEADER_CACHE_CONTROL, fiobj_dup(HTTP_HVALUE_MAX_AGE));
465
+ /* set last-modified */
466
+ FIOBJ last_modified_str = fiobj_str_buf(32);
467
+ fiobj_str_resize(
468
+ last_modified_str, http_time2str(fiobj_obj2cstr(last_modified_str).data, file_data.st_mtime));
469
+ http_set_header(h, HTTP_HEADER_LAST_MODIFIED, last_modified_str);
472
470
  /* set & test etag */
473
- uint64_t etag = (uint64_t)file_data.st_size;
474
- etag ^= (uint64_t)file_data.st_mtime;
475
- etag = fiobj_hash_string(&etag, sizeof(uint64_t));
476
- FIOBJ etag_str = fiobj_str_buf(32);
477
- fiobj_str_resize(etag_str,
478
- fio_base64_encode(fiobj_obj2cstr(etag_str).data,
479
- (void *)&etag, sizeof(uint64_t)));
471
+ FIOBJ etag_str = fiobj_str_buf(1);
472
+ fiobj_str_printf(etag_str, "%lx-%llx", file_data.st_mtime, file_data.st_size);
480
473
  /* set */
481
474
  http_set_header(h, HTTP_HEADER_ETAG, etag_str);
482
475
  /* test */
@@ -499,7 +492,7 @@ found_file:
499
492
  if (!ifrange_hash)
500
493
  ifrange_hash = fiobj_hash_string("if-range", 8);
501
494
  FIOBJ tmp = fiobj_hash_get2(h->headers, ifrange_hash);
502
- if (tmp && fiobj_iseq(tmp, etag_str)) {
495
+ if (tmp && !(fiobj_iseq(tmp, etag_str) || fiobj_iseq(tmp, last_modified_str))) {
503
496
  fiobj_hash_delete2(h->headers, range_hash);
504
497
  } else {
505
498
  tmp = fiobj_hash_get2(h->headers, range_hash);
@@ -513,26 +506,30 @@ found_file:
513
506
  char *pos = range.data + 6;
514
507
  int64_t start_at = 0, end_at = 0;
515
508
  start_at = fio_atol(&pos);
516
- if (start_at >= file_data.st_size)
517
- goto open_file;
518
509
  if (start_at >= 0) {
519
510
  pos++;
520
511
  end_at = fio_atol(&pos);
521
- if (end_at <= 0)
522
- goto open_file;
523
512
  }
524
513
  /* we ignore multimple ranges, only responding with the first range. */
525
- if (start_at < 0) {
526
- if (0 - start_at < file_data.st_size) {
527
- offset = file_data.st_size - start_at;
528
- length = 0 - start_at;
529
- }
530
- } else if (end_at) {
514
+ if (end_at) {
515
+ /* "Range bytes=100-200": bytes between `start_at` and `end_at` are requested */
516
+ if (start_at < 0 || end_at <= start_at || end_at >= length)
517
+ goto invalid_range;
518
+
531
519
  offset = start_at;
532
520
  length = end_at - start_at + 1;
533
- if (length + start_at > file_data.st_size || length <= 0)
534
- length = length - start_at;
521
+ } else if (start_at < 0) {
522
+ /* "Range bytes=-100": the last `start_at` bytes are requested */
523
+ if (0 - start_at >= length)
524
+ goto invalid_range;
525
+
526
+ offset = file_data.st_size + start_at;
527
+ length = 0 - start_at;
535
528
  } else {
529
+ /* "Range bytes=100-": all bytes starting at `start_at` are requested */
530
+ if (start_at >= length)
531
+ goto invalid_range;
532
+
536
533
  offset = start_at;
537
534
  length = length - start_at;
538
535
  }
@@ -612,6 +609,14 @@ open_file:
612
609
  }
613
610
  http_sendfile(h, file, length, offset);
614
611
  return 0;
612
+ invalid_range:
613
+ {
614
+ FIOBJ crange = fiobj_str_buf(1);
615
+ fiobj_str_printf(crange, "bytes */%lu", (unsigned long)file_data.st_size);
616
+ http_set_header(h, HTTP_HEADER_CONTENT_RANGE, crange);
617
+ http_send_error(h, 416);
618
+ return 0;
619
+ }
615
620
  }
616
621
 
617
622
  /**
@@ -131,10 +131,9 @@ struct IodineStorage_s IodineStore = {
131
131
  /** Initializes the storage unit for first use. */
132
132
  void iodine_storage_init(void) {
133
133
  fio_store_capa_require(&iodine_storage, 512);
134
- VALUE tmp =
135
- rb_define_class_under(rb_cObject, "IodineObjectStorage", rb_cObject);
136
- VALUE storage_obj =
137
- TypedData_Wrap_Struct(tmp, &storage_type_struct, &iodine_storage);
134
+ VALUE tmp = rb_define_class_under(rb_cObject, "IodineObjectStorage", rb_cObject);
135
+ rb_undef_alloc_func(tmp);
136
+ VALUE storage_obj = TypedData_Wrap_Struct(tmp, &storage_type_struct, &iodine_storage);
138
137
  // rb_global_variable(&iodine_storage_obj);
139
138
  rb_ivar_set(IodineModule, rb_intern2("storage", 7), storage_obj);
140
139
  rb_define_module_function(IodineBaseModule, "db_print_protected_objects",
@@ -1,3 +1,3 @@
1
1
  module Iodine
2
- VERSION = '3.1.0'.freeze
2
+ VERSION = '3.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rage-iodine
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-01 00:00:00.000000000 Z
11
+ date: 2024-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake