@@ -109,12 +109,14 @@ def test_multi_get_tracing
109
109
url_confs . each do |conf |
110
110
headers = conf [ :headers ] || { }
111
111
assert headers [ 'X-Trace' ]
112
+ assert headers [ 'Custom' ]
113
+ assert_match /specialvalue/ , headers [ 'Custom' ]
112
114
assert sampled? ( headers [ 'X-Trace' ] )
113
115
end
114
116
true
115
117
end
116
118
117
- easy_options = { :follow_location => true }
119
+ easy_options = { :follow_location => true , :headers => { 'Custom' => 'specialvalue' } }
118
120
multi_options = { :pipeline => false }
119
121
120
122
urls = [ ]
@@ -192,13 +194,15 @@ def test_multi_perform_tracing
192
194
urls . each do |url |
193
195
cu = Curl ::Easy . new ( url ) do |curl |
194
196
curl . follow_location = true
197
+ curl . headers = { 'Custom' => 'specialvalue' }
195
198
end
196
199
m . add cu
197
200
end
198
201
199
202
m . perform do
200
203
m . requests . each do |request |
201
204
assert request . headers [ 'X-Trace' ]
205
+ assert request . headers [ 'Custom' ]
202
206
assert sampled? ( request . headers [ 'X-Trace' ] )
203
207
end
204
208
end
@@ -234,6 +238,74 @@ def test_multi_perform_tracing_not_sampling
234
238
end
235
239
end
236
240
end
241
+
242
+ # preserve custom headers
243
+ #
244
+ # this calls Curl::Easy.http
245
+ def test_preserves_custom_headers_on_get
246
+ stub_request ( :get , "http://127.0.0.6:8101/" ) . to_return ( status : 200 , body : "" , headers : { } )
247
+
248
+ AppOpticsAPM ::API . start_trace ( 'curb_tests' ) do
249
+ Curl . get ( "http://127.0.0.6:8101/" ) do |curl |
250
+ curl . headers = { 'Custom' => 'specialvalue' }
251
+ end
252
+ end
253
+
254
+ assert_requested :get , "http://127.0.0.6:8101/" , headers : { 'Custom' => 'specialvalue' } , times : 1
255
+ end
256
+
257
+ # The following test can't use WebMock because it interferes with our instrumentation
258
+ def test_preserves_custom_headers_on_http_put
259
+ WebMock . disable!
260
+
261
+ curl = Curl ::Easy . new ( "http://127.0.0.1:8101/" )
262
+ curl . headers = { 'Custom' => 'specialvalue4' }
263
+
264
+ AppOpticsAPM ::API . start_trace ( 'curb_tests' ) do
265
+ curl . http_put nil
266
+ end
267
+
268
+ assert curl . headers
269
+ assert curl . headers [ 'X-Trace' ]
270
+ assert curl . headers [ 'Custom' ]
271
+ assert_match /^2B[0-9,A-F]*01$/ , curl . headers [ 'X-Trace' ]
272
+ assert_match /specialvalue4/ , curl . headers [ 'Custom' ]
273
+ end
274
+
275
+ def test_preserves_custom_headers_on_http_post
276
+ WebMock . disable!
277
+
278
+ curl = Curl ::Easy . new ( "http://127.0.0.1:8101/" )
279
+ curl . headers = { 'Custom' => 'specialvalue4' }
280
+
281
+ AppOpticsAPM ::API . start_trace ( 'curb_tests' ) do
282
+ curl . http_post
283
+ end
284
+
285
+ assert curl . headers
286
+ assert curl . headers [ 'X-Trace' ]
287
+ assert curl . headers [ 'Custom' ]
288
+ assert_match /^2B[0-9,A-F]*01$/ , curl . headers [ 'X-Trace' ]
289
+ assert_match /specialvalue4/ , curl . headers [ 'Custom' ]
290
+ end
291
+
292
+ def test_preserves_custom_headers_on_perform
293
+ WebMock . disable!
294
+
295
+ curl = Curl ::Easy . new ( "http://127.0.0.1:8101/" )
296
+ curl . headers = { 'Custom' => 'specialvalue4' }
297
+
298
+ AppOpticsAPM ::API . start_trace ( 'curb_tests' ) do
299
+ curl . perform
300
+ end
301
+
302
+ assert curl . headers
303
+ assert curl . headers [ 'X-Trace' ]
304
+ assert curl . headers [ 'Custom' ]
305
+ assert_match /^2B[0-9,A-F]*01$/ , curl . headers [ 'X-Trace' ]
306
+ assert_match /specialvalue4/ , curl . headers [ 'Custom' ]
307
+ end
308
+
237
309
end
238
310
end
239
311
0 commit comments