Module: Linzer::HTTP::StructuredField
- Defined in:
- lib/linzer/http/structured_field.rb
Overview
Utilities for serializing HTTP Structured Fields as defined in RFC 8941.
This module currently provides helpers for serializing HTTP Message Signature parameters as used by RFC 9421.
Constant Summary collapse
- InnerList =
Starry::InnerList
- Item =
Starry::Item
Class Method Summary collapse
-
.parse_dictionary(str, field_name: nil) ⇒ Hash<String, Object>
Parses an RFC 8941 Structured Field Dictionary.
-
.parse_item(item) ⇒ Starry::Item
Parses an RFC 8941 Structured Field Item.
-
.parse_list(list) ⇒ Array<Object>
Parses an RFC 8941 Structured Field List.
-
.serialize(obj) ⇒ String
Serializes an object into RFC 8941 Structured Field format.
-
.serialize_dictionary(hsh) ⇒ String
Serializes a dictionary into RFC 8941 Structured Field format.
-
.serialize_item(item) ⇒ String
Serializes a Structured Field Item into RFC 8941 format.
-
.serialize_list(arr) ⇒ String
Serializes a list into RFC 8941 Structured Field format.
-
.serialize_parameters(parameters) ⇒ String
Serializes Structured Field Parameters into RFC 8941 format.
Class Method Details
.parse_dictionary(str, field_name: nil) ⇒ Hash<String, Object>
Parses an RFC 8941 Structured Field Dictionary.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/linzer/http/structured_field.rb', line 24 def self.parse_dictionary(str, field_name: nil) Starry.parse_dictionary(str) # rescue Starry::ParseError => ex # https://github.com/takemar/starry/pull/4 rescue => ex cannot_parse = "Cannot parse %sfield!" raise Error, cannot_parse % [field_name ? "\"#{field_name}\" " : nil], cause: ex end |
.parse_item(item) ⇒ Starry::Item
Parses an RFC 8941 Structured Field Item.
42 43 44 45 46 47 48 |
# File 'lib/linzer/http/structured_field.rb', line 42 def self.parse_item(item) Starry.parse_item(item) # rescue Starry::ParseError => ex # https://github.com/takemar/starry/pull/4 rescue => ex raise Error, "Invalid/unparseable HTTP field item", cause: ex end |
.parse_list(list) ⇒ Array<Object>
Parses an RFC 8941 Structured Field List.
57 58 59 60 61 62 63 |
# File 'lib/linzer/http/structured_field.rb', line 57 def self.parse_list(list) Starry.parse_list(list) # rescue Starry::ParseError => ex # https://github.com/takemar/starry/pull/4 rescue => ex raise Error, "Invalid/unparseable HTTP field list", cause: ex end |
.serialize(obj) ⇒ String
Serializes an object into RFC 8941 Structured Field format.
102 103 104 105 106 |
# File 'lib/linzer/http/structured_field.rb', line 102 def self.serialize(obj) Starry.serialize(obj) rescue Starry::SerializeError => ex raise Error, ex., cause: ex end |
.serialize_dictionary(hsh) ⇒ String
Serializes a dictionary into RFC 8941 Structured Field format.
72 73 74 75 76 77 78 |
# File 'lib/linzer/http/structured_field.rb', line 72 def self.serialize_dictionary(hsh) Starry.serialize_dictionary(hsh) # rescue Starry::SerializeError => ex # https://github.com/takemar/starry/pull/4 rescue => ex raise Error, ex., cause: ex end |
.serialize_item(item) ⇒ String
Serializes a Structured Field Item into RFC 8941 format.
This helper serializes a single Structured Field Item, such as a string, integer, token, boolean, date, byte sequence, or an already constructed Starry::Item.
119 120 121 122 123 |
# File 'lib/linzer/http/structured_field.rb', line 119 def self.serialize_item(item) Starry.serialize_item(item) rescue Starry::SerializeError => ex raise Error, ex., cause: ex end |
.serialize_list(arr) ⇒ String
Serializes a list into RFC 8941 Structured Field format.
87 88 89 90 91 92 93 |
# File 'lib/linzer/http/structured_field.rb', line 87 def self.serialize_list(arr) Starry.serialize_list(arr) # rescue Starry::SerializeError => ex # https://github.com/takemar/starry/pull/4 rescue => ex raise Error, ex., cause: ex end |
.serialize_parameters(parameters) ⇒ String
Serializes Structured Field Parameters into RFC 8941 format.
Parameters are serialized according to the Structured Fields parameter syntax defined in RFC 8941 Section 3.1.2.
136 137 138 139 140 141 142 |
# File 'lib/linzer/http/structured_field.rb', line 136 def self.serialize_parameters(parameters) Starry.serialize_parameters(parameters) # rescue Starry::SerializeError => ex # https://github.com/takemar/starry/pull/4 rescue => ex raise Error, ex., cause: ex end |