Module: Iodine::Rack::Utils
- Defined in:
- ext/iodine/iodine_helpers.c
Class Method Summary collapse
-
.decode_path(str) ⇒ Object
Decodes a percent encoded String (normally the “path” of a request), returning a new String with the decoded data.
-
.decode_path!(str) ⇒ Object
Decodes a percent encoded String (normally the “path” of a request), editing the String in place.
-
.decode_url(str) ⇒ Object
Decodes a URL encoded String, returning a new String with the decoded data.
-
.decode_url!(str) ⇒ Object
Decodes a URL encoded String in place.
-
.rfc2109(rtm) ⇒ Object
Takes ‘time` and returns a faster (though less localized) HTTP Date formatted String.
-
.rfc2822(rtm) ⇒ Object
Takes ‘time` and returns a faster (though less localized) HTTP Date formatted String.
-
.time2str(*args) ⇒ Object
Takes an optional Integer for Unix Time and returns a faster (though less localized) HTTP Date formatted String.
Class Method Details
.decode_path(str) ⇒ Object
Decodes a percent encoded String (normally the “path” of a request), returning a new String with the decoded data.
76 77 78 79 80 81 82 83 84 85 86 |
# File 'ext/iodine/iodine_helpers.c', line 76 static VALUE path_decode(VALUE self, VALUE str) { Check_Type(str, T_STRING); VALUE str2 = rb_str_buf_new(RSTRING_LEN(str)); ssize_t len = http_decode_path(RSTRING_PTR(str2), RSTRING_PTR(str), RSTRING_LEN(str)); if (len < 0) rb_raise(rb_eRuntimeError, "Malformed URL path string - couldn't decode."); rb_str_set_len(str2, len); return str2; (void)self; } |
.decode_path!(str) ⇒ Object
Decodes a percent encoded String (normally the “path” of a request), editing the String in place.
Raises an exception on error… but this might result in a partially decoded String.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'ext/iodine/iodine_helpers.c', line 59 static VALUE path_decode_inplace(VALUE self, VALUE str) { Check_Type(str, T_STRING); ssize_t len = http_decode_path(RSTRING_PTR(str), RSTRING_PTR(str), RSTRING_LEN(str)); if (len < 0) rb_raise(rb_eRuntimeError, "Malformed URL path string - couldn't decode (String " "might have been partially altered)."); rb_str_set_len(str, len); return str; (void)self; } |
.decode_url(str) ⇒ Object
Decodes a URL encoded String, returning a new String with the decoded data.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'ext/iodine/iodine_helpers.c', line 40 static VALUE url_decode(VALUE self, VALUE str) { Check_Type(str, T_STRING); VALUE str2 = rb_str_buf_new(RSTRING_LEN(str)); ssize_t len = http_decode_url(RSTRING_PTR(str2), RSTRING_PTR(str), RSTRING_LEN(str)); if (len < 0) rb_raise(rb_eRuntimeError, "Malformed URL string - couldn't decode."); rb_str_set_len(str2, len); return str2; (void)self; } |
.decode_url!(str) ⇒ Object
Decodes a URL encoded String in place.
Raises an exception on error… but this might result in a partially decoded String.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'ext/iodine/iodine_helpers.c', line 25 static VALUE url_decode_inplace(VALUE self, VALUE str) { Check_Type(str, T_STRING); ssize_t len = http_decode_url(RSTRING_PTR(str), RSTRING_PTR(str), RSTRING_LEN(str)); if (len < 0) rb_raise(rb_eRuntimeError, "Malformed URL string - couldn't decode (String " "might have been partially altered)."); rb_str_set_len(str, len); return str; (void)self; } |
.rfc2109(rtm) ⇒ Object
Takes ‘time` and returns a faster (though less localized) HTTP Date formatted String.
Iodine::Rack.rfc2109(Time.now) => "Sun, 11-Jun-2017 06:14:08 GMT"
Iodine::Rack.rfc2109(0) => "Sun, 11-Jun-2017 06:14:08 GMT"
Since Iodine uses time caching within it’s reactor, using the default value (by passing 0) will be faster than providing an explicit time using ‘Time.now`.
195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'ext/iodine/iodine_helpers.c', line 195 static VALUE iodine_rfc2109(VALUE self, VALUE rtm) { time_t last_tick; rtm = rb_funcallv(rtm, iodine_to_i_func_id, 0, NULL); last_tick = FIX2ULONG(rtm) ? FIX2ULONG(rtm) : facil_last_tick().tv_sec; VALUE str = rb_str_buf_new(32); struct tm tm; http_gmtime(last_tick, &tm); size_t len = http_date2rfc2109(RSTRING_PTR(str), &tm); rb_str_set_len(str, len); return str; (void)self; } |
.rfc2822(rtm) ⇒ Object
Takes ‘time` and returns a faster (though less localized) HTTP Date formatted String.
Iodine::Rack.rfc2822(Time.now) => "Sun, 11 Jun 2017 06:14:08 -0000"
Iodine::Rack.rfc2822(0) => "Sun, 11 Jun 2017 06:14:08 -0000"
Since Iodine uses time caching within it’s reactor, using the default value (by passing 0) will be faster than providing an explicit time using ‘Time.now`.
169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'ext/iodine/iodine_helpers.c', line 169 static VALUE iodine_rfc2822(VALUE self, VALUE rtm) { time_t last_tick; rtm = rb_funcallv(rtm, iodine_to_i_func_id, 0, NULL); last_tick = FIX2ULONG(rtm) ? FIX2ULONG(rtm) : facil_last_tick().tv_sec; VALUE str = rb_str_buf_new(34); struct tm tm; http_gmtime(last_tick, &tm); size_t len = http_date2rfc2822(RSTRING_PTR(str), &tm); rb_str_set_len(str, len); return str; (void)self; } |
.time2str(*args) ⇒ Object
Takes an optional Integer for Unix Time and returns a faster (though less localized) HTTP Date formatted String.
Iodine::Rack.time2str => "Sun, 11 Jun 2017 06:14:08 GMT"
Iodine::Rack.time2str(Time.now.to_i) => "Wed, 15 Nov 1995 06:25:24 GMT"
Since Iodine uses time caching within it’s reactor, using the default value (now) will be faster than providing an explicit time using ‘Time.now.to_i`.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'ext/iodine/iodine_helpers.c', line 134 static VALUE date_str(int argc, VALUE *argv, VALUE self) { if (argc > 1) rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0..1).", argc); time_t last_tick; if (argc) { if (TYPE(argv[0]) != T_FIXNUM) argv[0] = rb_funcallv(argv[0], iodine_to_i_func_id, 0, NULL); Check_Type(argv[0], T_FIXNUM); last_tick = FIX2ULONG(argv[0]) ? FIX2ULONG(argv[0]) : facil_last_tick().tv_sec; } else last_tick = facil_last_tick().tv_sec; VALUE str = rb_str_buf_new(32); struct tm tm; http_gmtime(last_tick, &tm); size_t len = http_date2str(RSTRING_PTR(str), &tm); rb_str_set_len(str, len); return str; (void)self; } |