Class: OpenC3::HttpAccessor
Instance Attribute Summary
Attributes inherited from Accessor
#packet
Instance Method Summary
collapse
Methods inherited from Accessor
#args, convert_to_type, read_item, #read_items, read_items, write_item, #write_items, write_items
Constructor Details
#initialize(packet, body_accessor = 'FormAccessor', *body_accessor_args) ⇒ HttpAccessor
Returns a new instance of HttpAccessor.
23
24
25
26
27
28
29
30
31
|
# File 'lib/openc3/accessors/http_accessor.rb', line 23
def initialize(packet, body_accessor = 'FormAccessor', *body_accessor_args)
super(packet)
@args << body_accessor
body_accessor_args.each do |arg|
@args << arg
end
klass = OpenC3.require_class(body_accessor)
@body_accessor = klass.new(packet, *body_accessor_args)
end
|
Instance Method Details
#enforce_derived_write_conversion(item) ⇒ Object
136
137
138
139
140
141
142
143
|
# File 'lib/openc3/accessors/http_accessor.rb', line 136
def enforce_derived_write_conversion(item)
case item.name
when 'HTTP_STATUS', 'HTTP_PATH', 'HTTP_METHOD', 'HTTP_PACKET', 'HTTP_ERROR_PACKET', /^HTTP_QUERY_/, /^HTTP_HEADER_/
return false
else
return @body_accessor.enforce_derived_write_conversion
end
end
|
#enforce_encoding ⇒ Object
124
125
126
|
# File 'lib/openc3/accessors/http_accessor.rb', line 124
def enforce_encoding
return @body_accessor.enforce_encoding
end
|
#enforce_length ⇒ Object
128
129
130
|
# File 'lib/openc3/accessors/http_accessor.rb', line 128
def enforce_length
return @body_accessor.enforce_length
end
|
#enforce_short_buffer_allowed ⇒ Object
132
133
134
|
# File 'lib/openc3/accessors/http_accessor.rb', line 132
def enforce_short_buffer_allowed
return @body_accessor.enforce_short_buffer_allowed
end
|
#read_item(item, buffer) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/openc3/accessors/http_accessor.rb', line 33
def read_item(item, buffer)
item_name = item.name
case item_name
when 'HTTP_STATUS'
return nil unless @packet.
return @packet.['HTTP_STATUS']
when 'HTTP_PATH'
return nil unless @packet.
return @packet.['HTTP_PATH']
when 'HTTP_METHOD'
return nil unless @packet.
return @packet.['HTTP_METHOD']
when 'HTTP_PACKET'
return nil unless @packet.
return @packet.['HTTP_PACKET']
when 'HTTP_ERROR_PACKET'
return nil unless @packet.
return @packet.['HTTP_ERROR_PACKET']
when /^HTTP_QUERY_/
return nil unless @packet.
if item.key
query_name = item.key
else
query_name = item_name[11..-1]
end
queries = @packet.['HTTP_QUERIES']
if queries
return queries[query_name]
else
return nil
end
when /^HTTP_HEADER_/
return nil unless @packet.
if item.key
= item.key
else
= item_name[12..-1]
end
= @packet.['HTTP_HEADERS']
if
return []
else
return nil
end
else
return @body_accessor.read_item(item, buffer)
end
end
|
#write_item(item, value, buffer) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/openc3/accessors/http_accessor.rb', line 82
def write_item(item, value, buffer)
item_name = item.name
case item_name
when 'HTTP_STATUS'
@packet. ||= {}
@packet.['HTTP_STATUS'] = value.to_i
when 'HTTP_PATH'
@packet. ||= {}
@packet.['HTTP_PATH'] = value.to_s
when 'HTTP_METHOD'
@packet. ||= {}
@packet.['HTTP_METHOD'] = value.to_s.downcase
when 'HTTP_PACKET'
@packet. ||= {}
@packet.['HTTP_PACKET'] = value.to_s.upcase
when 'HTTP_ERROR_PACKET'
@packet. ||= {}
@packet.['HTTP_ERROR_PACKET'] = value.to_s.upcase
when /^HTTP_QUERY_/
@packet. ||= {}
if item.key
query_name = item.key
else
query_name = item_name[11..-1]
end
queries = @packet.['HTTP_QUERIES'] ||= {}
queries[query_name] = value.to_s
when /^HTTP_HEADER_/
@packet. ||= {}
if item.key
= item.key
else
= item_name[12..-1]
end
= @packet.['HTTP_HEADERS'] ||= {}
[] = value.to_s
else
@body_accessor.write_item(item, value, buffer)
end
return value
end
|