@@ -49,51 +49,52 @@ public static Channel CreateChannel(this OtlpExporterOptions options)
49
49
public static Metadata GetMetadataFromHeaders ( this OtlpExporterOptions options ) => options . GetHeaders < Metadata > ( ( m , k , v ) => m . Add ( k , v ) ) ;
50
50
#endif
51
51
52
- public static THeaders GetHeaders < THeaders > ( this OtlpExporterOptions options , Action < THeaders , string , string > addHeader )
53
- where THeaders : new ( )
54
- {
55
- var optionHeaders = options . Headers ;
56
- var headers = new THeaders ( ) ;
57
- if ( ! string . IsNullOrEmpty ( optionHeaders ) )
52
+ public static THeaders GetHeaders < THeaders > ( this OtlpExporterOptions options , Action < THeaders , string , string > addHeader )
53
+ where THeaders : new ( )
58
54
{
59
- optionHeaders = Uri . UnescapeDataString ( optionHeaders ) ;
60
- ReadOnlySpan < char > headersSpan = optionHeaders . AsSpan ( ) ;
61
-
62
- while ( ! headersSpan . IsEmpty )
55
+ var optionHeaders = options . Headers ;
56
+ var headers = new THeaders ( ) ;
57
+ if ( ! string . IsNullOrEmpty ( optionHeaders ) )
63
58
{
64
- int commaIndex = headersSpan . IndexOf ( ',' ) ;
65
- ReadOnlySpan < char > pair ;
66
- if ( commaIndex == - 1 )
67
- {
68
- pair = headersSpan ;
69
- headersSpan = ReadOnlySpan < char > . Empty ;
70
- }
71
- else
72
- {
73
- pair = headersSpan . Slice ( 0 , commaIndex ) ;
74
- headersSpan = headersSpan . Slice ( commaIndex + 1 ) ;
75
- }
59
+ // According to the specification, URL-encoded headers must be supported.
60
+ optionHeaders = Uri . UnescapeDataString ( optionHeaders ) ;
61
+ ReadOnlySpan < char > headersSpan = optionHeaders . AsSpan ( ) ;
76
62
77
- int equalIndex = pair . IndexOf ( '=' ) ;
78
- if ( equalIndex == - 1 )
63
+ while ( ! headersSpan . IsEmpty )
79
64
{
80
- throw new ArgumentException ( "Headers provided in an invalid format." ) ;
65
+ int commaIndex = headersSpan . IndexOf ( ',' ) ;
66
+ ReadOnlySpan < char > pair ;
67
+ if ( commaIndex == - 1 )
68
+ {
69
+ pair = headersSpan ;
70
+ headersSpan = ReadOnlySpan < char > . Empty ;
71
+ }
72
+ else
73
+ {
74
+ pair = headersSpan . Slice ( 0 , commaIndex ) ;
75
+ headersSpan = headersSpan . Slice ( commaIndex + 1 ) ;
76
+ }
77
+
78
+ int equalIndex = pair . IndexOf ( '=' ) ;
79
+ if ( equalIndex == - 1 )
80
+ {
81
+ throw new ArgumentException ( "Headers provided in an invalid format." ) ;
82
+ }
83
+
84
+ var key = pair . Slice ( 0 , equalIndex ) . ToString ( ) . Trim ( ) ;
85
+ var value = pair . Slice ( equalIndex + 1 ) . ToString ( ) . Trim ( ) ;
86
+ addHeader ( headers , key , value ) ;
81
87
}
88
+ }
82
89
83
- var key = pair . Slice ( 0 , equalIndex ) . ToString ( ) . Trim ( ) ;
84
- var value = pair . Slice ( equalIndex + 1 ) . ToString ( ) . Trim ( ) ;
85
- addHeader ( headers , key , value ) ;
90
+ foreach ( var header in OtlpExporterOptions . StandardHeaders )
91
+ {
92
+ addHeader ( headers , header . Key , header . Value ) ;
86
93
}
87
- }
88
94
89
- foreach ( var header in OtlpExporterOptions . StandardHeaders )
90
- {
91
- addHeader ( headers , header . Key , header . Value ) ;
95
+ return headers ;
92
96
}
93
97
94
- return headers ;
95
- }
96
-
97
98
98
99
public static OtlpExporterTransmissionHandler GetExportTransmissionHandler ( this OtlpExporterOptions options , ExperimentalOptions experimentalOptions , OtlpSignalType otlpSignalType )
99
100
{
0 commit comments