Module: SiteHub::CookieRewriting
- Included in:
- Middleware::ReverseProxy
- Defined in:
- lib/sitehub/cookie_rewriting.rb
Overview
TODO: - change in to object and remove .reek exclusions for UtilityFunction
Constant Summary collapse
- ENDING_WITH_NEWLINE =
/#{NEW_LINE}$/
Instance Method Summary collapse
- #cookies_hash_to_string(cookies_hash) ⇒ Object
- #cookies_string_as_hash(cookie_string) ⇒ Object
- #rewrite_cookies(headers, substitute_domain:) ⇒ Object
- #update_domain(domain_attribute, substitute_domain) ⇒ Object
Instance Method Details
#cookies_hash_to_string(cookies_hash) ⇒ Object
27 28 29 30 31 |
# File 'lib/sitehub/cookie_rewriting.rb', line 27 def () .values.inject(EMPTY_STRING.dup) do |, | << "#{}#{NEW_LINE}" end.sub(ENDING_WITH_NEWLINE, EMPTY_STRING) end |
#cookies_string_as_hash(cookie_string) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/sitehub/cookie_rewriting.rb', line 33 def () .lines.each_with_object({}) do |, | = SiteHub::Cookie.new() [.name] = end end |
#rewrite_cookies(headers, substitute_domain:) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/sitehub/cookie_rewriting.rb', line 8 def (headers, substitute_domain:) = (headers[Constants::HttpHeaderKeys::SET_COOKIE]) .values.each do || domain_attribute = .find(:domain) || next update_domain(domain_attribute, substitute_domain) end headers[Constants::HttpHeaderKeys::SET_COOKIE] = () end |
#update_domain(domain_attribute, substitute_domain) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/sitehub/cookie_rewriting.rb', line 18 def update_domain(domain_attribute, substitute_domain) substitute = substitute_domain.dup if domain_attribute.value.start_with?(FULL_STOP) domain_attribute.update(substitute.prepend(FULL_STOP)) else domain_attribute.update(substitute) end end |