@@ -44,8 +44,9 @@ impl HostHandle {
44
44
pub struct HostSettings {
45
45
abi_version : AbiVersion ,
46
46
quiet : bool ,
47
+ effective_context_id : i32 ,
47
48
tick_period_millis : Duration ,
48
- header_map_pairs : HashMap < i32 , HashMap < String , String > > ,
49
+ header_map_pairs : HashMap < i32 , Vec < ( String , String ) > > ,
49
50
buffer_bytes : HashMap < i32 , Bytes > ,
50
51
}
51
52
@@ -54,6 +55,7 @@ impl HostSettings {
54
55
HostSettings {
55
56
abi_version : abi_version,
56
57
quiet : quiet,
58
+ effective_context_id : -1 ,
57
59
tick_period_millis : Duration :: new ( 0 , 0 ) ,
58
60
header_map_pairs : default_header_map_pairs ( ) ,
59
61
buffer_bytes : default_buffer_bytes ( ) ,
@@ -76,6 +78,14 @@ impl HostSettings {
76
78
self . quiet
77
79
}
78
80
81
+ pub fn set_effective_context ( & mut self , effective_context_id : i32 ) {
82
+ self . effective_context_id = effective_context_id;
83
+ }
84
+
85
+ pub fn get_effective_context ( & mut self ) -> i32 {
86
+ self . effective_context_id
87
+ }
88
+
79
89
pub fn reset_tick_period_millis ( & mut self ) {
80
90
self . tick_period_millis = Duration :: from_millis ( 0u64 ) ;
81
91
}
@@ -107,9 +117,9 @@ impl HostSettings {
107
117
}
108
118
109
119
pub fn set_header_map_pairs ( & mut self , map_type : i32 , header_map_pairs : Vec < ( & str , & str ) > ) {
110
- let mut header_map = HashMap :: new ( ) ;
120
+ let mut header_map = Vec :: new ( ) ;
111
121
for ( header_map_key, header_map_value) in header_map_pairs. into_iter ( ) {
112
- header_map. insert ( header_map_key. to_string ( ) , header_map_value. to_string ( ) ) ;
122
+ header_map. push ( ( header_map_key. to_string ( ) , header_map_value. to_string ( ) ) ) ;
113
123
}
114
124
self . header_map_pairs . insert ( map_type, header_map) ;
115
125
}
@@ -124,9 +134,14 @@ impl HostSettings {
124
134
}
125
135
126
136
pub fn get_header_map_value ( & self , map_type : i32 , header_map_key : & str ) -> Option < String > {
137
+ let mut header_map_value: Option < String > = None ;
127
138
let header_map = self . header_map_pairs . get ( & map_type) . unwrap ( ) ;
128
- let header_map_value = header_map. get ( header_map_key) ;
129
- header_map_value. map ( |str_val| str_val. to_string ( ) )
139
+ for ( key, value) in header_map {
140
+ if key == header_map_key {
141
+ header_map_value = Some ( value. to_string ( ) ) ;
142
+ }
143
+ }
144
+ header_map_value
130
145
}
131
146
132
147
pub fn replace_header_map_value (
@@ -135,13 +150,27 @@ impl HostSettings {
135
150
header_map_key : & str ,
136
151
header_map_value : & str ,
137
152
) {
138
- let header_map = self . header_map_pairs . get_mut ( & map_type) . unwrap ( ) ;
139
- header_map. insert ( header_map_key. to_string ( ) , header_map_value. to_string ( ) ) ;
153
+ let mut new_header_map: Vec < ( String , String ) > = Vec :: new ( ) ;
154
+ let header_map = self . header_map_pairs . get ( & map_type) . unwrap ( ) ;
155
+ for ( key, value) in header_map {
156
+ if key != header_map_key {
157
+ new_header_map. push ( ( key. to_string ( ) , value. to_string ( ) ) ) ;
158
+ } else {
159
+ new_header_map. push ( ( key. to_string ( ) , header_map_value. to_string ( ) ) ) ;
160
+ }
161
+ }
162
+ self . header_map_pairs . insert ( map_type, new_header_map) ;
140
163
}
141
164
142
165
pub fn remove_header_map_value ( & mut self , map_type : i32 , header_map_key : & str ) {
143
- let header_map = self . header_map_pairs . get_mut ( & map_type) . unwrap ( ) ;
144
- header_map. remove ( header_map_key) ;
166
+ let mut new_header_map: Vec < ( String , String ) > = Vec :: new ( ) ;
167
+ let header_map = self . header_map_pairs . get ( & map_type) . unwrap ( ) ;
168
+ for ( key, value) in header_map {
169
+ if key != header_map_key {
170
+ new_header_map. push ( ( key. to_string ( ) , value. to_string ( ) ) ) ;
171
+ }
172
+ }
173
+ self . header_map_pairs . insert ( map_type, new_header_map) ;
145
174
}
146
175
147
176
pub fn add_header_map_value (
@@ -150,79 +179,91 @@ impl HostSettings {
150
179
header_map_key : & str ,
151
180
header_map_value : & str ,
152
181
) {
153
- let header_map = self . header_map_pairs . get_mut ( & map_type) . unwrap ( ) ;
154
- header_map. insert ( header_map_key. to_string ( ) , header_map_value. to_string ( ) ) ;
182
+ let mut key_found = false ;
183
+ let mut new_header_map: Vec < ( String , String ) > = Vec :: new ( ) ;
184
+ let header_map = self . header_map_pairs . get ( & map_type) . unwrap ( ) ;
185
+ for ( key, value) in header_map {
186
+ if key != header_map_key {
187
+ new_header_map. push ( ( key. to_string ( ) , value. to_string ( ) ) ) ;
188
+ } else {
189
+ key_found = true ;
190
+ }
191
+ }
192
+ if !key_found {
193
+ new_header_map. push ( ( header_map_key. to_string ( ) , header_map_value. to_string ( ) ) ) ;
194
+ }
195
+ self . header_map_pairs . insert ( map_type, new_header_map) ;
155
196
}
156
197
}
157
198
158
199
// functions to retrieve default values
159
- pub fn default_header_map_pairs ( ) -> HashMap < i32 , HashMap < String , String > > {
200
+ pub fn default_header_map_pairs ( ) -> HashMap < i32 , Vec < ( String , String ) > > {
160
201
let mut default_header_maps = HashMap :: new ( ) ;
161
202
162
- let mut http_on_request_headers = HashMap :: new ( ) ;
163
- http_on_request_headers. insert ( ":method" . to_string ( ) , "GET" . to_string ( ) ) ;
164
- http_on_request_headers. insert (
203
+ let mut http_on_request_headers = Vec :: new ( ) ;
204
+ http_on_request_headers. push ( ( ":method" . to_string ( ) , "GET" . to_string ( ) ) ) ;
205
+ http_on_request_headers. push ( (
165
206
":path" . to_string ( ) ,
166
207
"/default/request/headers/path" . to_string ( ) ,
167
- ) ;
168
- http_on_request_headers. insert ( ":authority" . to_string ( ) , "abi_test_harness" . to_string ( ) ) ;
208
+ ) ) ;
209
+ http_on_request_headers. push ( ( ":authority" . to_string ( ) , "abi_test_harness" . to_string ( ) ) ) ;
169
210
default_header_maps. insert ( MapType :: HttpRequestHeaders as i32 , http_on_request_headers) ;
170
211
171
- let mut http_on_request_trailers = HashMap :: new ( ) ;
172
- http_on_request_trailers. insert ( ":method" . to_string ( ) , "GET" . to_string ( ) ) ;
173
- http_on_request_trailers. insert (
212
+ let mut http_on_request_trailers = Vec :: new ( ) ;
213
+ http_on_request_trailers. push ( ( ":method" . to_string ( ) , "GET" . to_string ( ) ) ) ;
214
+ http_on_request_trailers. push ( (
174
215
":path" . to_string ( ) ,
175
216
"/default/request/trailers/path" . to_string ( ) ,
176
- ) ;
177
- http_on_request_trailers. insert ( ":authority" . to_string ( ) , "abi_test_harness" . to_string ( ) ) ;
217
+ ) ) ;
218
+ http_on_request_trailers. push ( ( ":authority" . to_string ( ) , "abi_test_harness" . to_string ( ) ) ) ;
178
219
default_header_maps. insert (
179
220
MapType :: HttpRequestTrailers as i32 ,
180
221
http_on_request_trailers,
181
222
) ;
182
223
183
- let mut http_on_response_headers = HashMap :: new ( ) ;
184
- http_on_response_headers. insert ( ":method" . to_string ( ) , "GET" . to_string ( ) ) ;
185
- http_on_response_headers. insert (
224
+ let mut http_on_response_headers = Vec :: new ( ) ;
225
+ http_on_response_headers. push ( ( ":method" . to_string ( ) , "GET" . to_string ( ) ) ) ;
226
+ http_on_response_headers. push ( (
186
227
":path" . to_string ( ) ,
187
228
"/default/response/headers/path" . to_string ( ) ,
188
- ) ;
189
- http_on_response_headers. insert ( ":authority" . to_string ( ) , "abi_test_harness" . to_string ( ) ) ;
229
+ ) ) ;
230
+ http_on_response_headers. push ( ( ":authority" . to_string ( ) , "abi_test_harness" . to_string ( ) ) ) ;
190
231
default_header_maps. insert (
191
232
MapType :: HttpResponseHeaders as i32 ,
192
233
http_on_response_headers,
193
234
) ;
194
235
195
- let mut http_on_response_trailers = HashMap :: new ( ) ;
196
- http_on_response_trailers. insert ( ":method" . to_string ( ) , "GET" . to_string ( ) ) ;
197
- http_on_response_trailers. insert (
236
+ let mut http_on_response_trailers = Vec :: new ( ) ;
237
+ http_on_response_trailers. push ( ( ":method" . to_string ( ) , "GET" . to_string ( ) ) ) ;
238
+ http_on_response_trailers. push ( (
198
239
":path" . to_string ( ) ,
199
240
"/default/response/trailers/path" . to_string ( ) ,
200
- ) ;
201
- http_on_response_trailers. insert ( ":authority" . to_string ( ) , "abi_test_harness" . to_string ( ) ) ;
241
+ ) ) ;
242
+ http_on_response_trailers. push ( ( ":authority" . to_string ( ) , "abi_test_harness" . to_string ( ) ) ) ;
202
243
default_header_maps. insert (
203
244
MapType :: HttpResponseTrailers as i32 ,
204
245
http_on_response_trailers,
205
246
) ;
206
247
207
- let mut http_call_response_headers = HashMap :: new ( ) ;
208
- http_call_response_headers. insert ( ":method" . to_string ( ) , "GET" . to_string ( ) ) ;
209
- http_call_response_headers. insert (
248
+ let mut http_call_response_headers = Vec :: new ( ) ;
249
+ http_call_response_headers. push ( ( ":method" . to_string ( ) , "GET" . to_string ( ) ) ) ;
250
+ http_call_response_headers. push ( (
210
251
":path" . to_string ( ) ,
211
252
"/default/call/response/headers/path" . to_string ( ) ,
212
- ) ;
213
- http_call_response_headers. insert ( ":authority" . to_string ( ) , "abi_test_harness" . to_string ( ) ) ;
253
+ ) ) ;
254
+ http_call_response_headers. push ( ( ":authority" . to_string ( ) , "abi_test_harness" . to_string ( ) ) ) ;
214
255
default_header_maps. insert (
215
256
MapType :: HttpCallResponseHeaders as i32 ,
216
257
http_call_response_headers,
217
258
) ;
218
259
219
- let mut http_call_response_trailers = HashMap :: new ( ) ;
220
- http_call_response_trailers. insert ( ":method" . to_string ( ) , "GET" . to_string ( ) ) ;
221
- http_call_response_trailers. insert (
260
+ let mut http_call_response_trailers = Vec :: new ( ) ;
261
+ http_call_response_trailers. push ( ( ":method" . to_string ( ) , "GET" . to_string ( ) ) ) ;
262
+ http_call_response_trailers. push ( (
222
263
":path" . to_string ( ) ,
223
264
"/default/call/response/trailers/path" . to_string ( ) ,
224
- ) ;
225
- http_call_response_trailers. insert ( ":authority" . to_string ( ) , "abi_test_harness" . to_string ( ) ) ;
265
+ ) ) ;
266
+ http_call_response_trailers. push ( ( ":authority" . to_string ( ) , "abi_test_harness" . to_string ( ) ) ) ;
226
267
default_header_maps. insert (
227
268
MapType :: HttpCallResponseTrailers as i32 ,
228
269
http_call_response_trailers,
0 commit comments