1
+ using System ;
2
+ using System . Collections . Generic ;
3
+
4
+ namespace ServiceStack ;
5
+
6
+ public static class HttpHeaders
7
+ {
8
+ public const string XParamOverridePrefix = "X-Param-Override-" ;
9
+
10
+ public const string XHttpMethodOverride = "X-Http-Method-Override" ;
11
+
12
+ public const string XAutoBatchCompleted = "X-AutoBatch-Completed" ; // How many requests were completed before first failure
13
+
14
+ public const string XTag = "X-Tag" ;
15
+
16
+ public const string XUserAuthId = "X-UAId" ;
17
+
18
+ public const string XTrigger = "X-Trigger" ; // Trigger Events on UserAgent
19
+
20
+ public const string XForwardedFor = "X-Forwarded-For" ; // IP Address
21
+
22
+ public const string XForwardedPort = "X-Forwarded-Port" ; // 80
23
+
24
+ public const string XForwardedProtocol = "X-Forwarded-Proto" ; // http or https
25
+
26
+ public const string XRealIp = "X-Real-IP" ;
27
+
28
+ public const string XLocation = "X-Location" ;
29
+
30
+ public const string XStatus = "X-Status" ;
31
+
32
+ public const string XPoweredBy = "X-Powered-By" ;
33
+
34
+ public const string Referer = "Referer" ;
35
+
36
+ public const string CacheControl = "Cache-Control" ;
37
+
38
+ public const string IfModifiedSince = "If-Modified-Since" ;
39
+
40
+ public const string IfUnmodifiedSince = "If-Unmodified-Since" ;
41
+
42
+ public const string IfNoneMatch = "If-None-Match" ;
43
+
44
+ public const string IfMatch = "If-Match" ;
45
+
46
+ public const string LastModified = "Last-Modified" ;
47
+
48
+ public const string Accept = "Accept" ;
49
+
50
+ public const string AcceptEncoding = "Accept-Encoding" ;
51
+
52
+ public const string ContentType = "Content-Type" ;
53
+
54
+ public const string ContentEncoding = "Content-Encoding" ;
55
+
56
+ public const string ContentLength = "Content-Length" ;
57
+
58
+ public const string ContentDisposition = "Content-Disposition" ;
59
+
60
+ public const string Location = "Location" ;
61
+
62
+ public const string SetCookie = "Set-Cookie" ;
63
+
64
+ public const string ETag = "ETag" ;
65
+
66
+ public const string Age = "Age" ;
67
+
68
+ public const string Expires = "Expires" ;
69
+
70
+ public const string Vary = "Vary" ;
71
+
72
+ public const string Authorization = "Authorization" ;
73
+
74
+ public const string WwwAuthenticate = "WWW-Authenticate" ;
75
+
76
+ public const string AllowOrigin = "Access-Control-Allow-Origin" ;
77
+
78
+ public const string AllowMethods = "Access-Control-Allow-Methods" ;
79
+
80
+ public const string AllowHeaders = "Access-Control-Allow-Headers" ;
81
+
82
+ public const string AllowCredentials = "Access-Control-Allow-Credentials" ;
83
+
84
+ public const string ExposeHeaders = "Access-Control-Expose-Headers" ;
85
+
86
+ public const string AccessControlMaxAge = "Access-Control-Max-Age" ;
87
+
88
+ public const string Origin = "Origin" ;
89
+
90
+ public const string RequestMethod = "Access-Control-Request-Method" ;
91
+
92
+ public const string RequestHeaders = "Access-Control-Request-Headers" ;
93
+
94
+ public const string AcceptRanges = "Accept-Ranges" ;
95
+
96
+ public const string ContentRange = "Content-Range" ;
97
+
98
+ public const string Range = "Range" ;
99
+
100
+ public const string SOAPAction = "SOAPAction" ;
101
+
102
+ public const string Allow = "Allow" ;
103
+
104
+ public const string AcceptCharset = "Accept-Charset" ;
105
+
106
+ public const string AcceptLanguage = "Accept-Language" ;
107
+
108
+ public const string Connection = "Connection" ;
109
+
110
+ public const string Cookie = "Cookie" ;
111
+
112
+ public const string ContentLanguage = "Content-Language" ;
113
+
114
+ public const string Expect = "Expect" ;
115
+
116
+ public const string Pragma = "Pragma" ;
117
+
118
+ public const string ProxyAuthenticate = "Proxy-Authenticate" ;
119
+
120
+ public const string ProxyAuthorization = "Proxy-Authorization" ;
121
+
122
+ public const string ProxyConnection = "Proxy-Connection" ;
123
+
124
+ public const string SetCookie2 = "Set-Cookie2" ;
125
+
126
+ public const string TE = "TE" ;
127
+
128
+ public const string Trailer = "Trailer" ;
129
+
130
+ public const string TransferEncoding = "Transfer-Encoding" ;
131
+
132
+ public const string Upgrade = "Upgrade" ;
133
+
134
+ public const string Via = "Via" ;
135
+
136
+ public const string Warning = "Warning" ;
137
+
138
+ public const string Date = "Date" ;
139
+ public const string Host = "Host" ;
140
+ public const string UserAgent = "User-Agent" ;
141
+
142
+ public static HashSet < string > RestrictedHeaders = new ( StringComparer . OrdinalIgnoreCase )
143
+ {
144
+ Accept ,
145
+ Connection ,
146
+ ContentLength ,
147
+ ContentType ,
148
+ Date ,
149
+ Expect ,
150
+ Host ,
151
+ IfModifiedSince ,
152
+ Range ,
153
+ Referer ,
154
+ TransferEncoding ,
155
+ UserAgent ,
156
+ ProxyConnection ,
157
+ } ;
158
+ }
159
+
160
+
161
+ public static class CompressionTypes
162
+ {
163
+ public static readonly string [ ] AllCompressionTypes =
164
+ {
165
+ #if NET6_0_OR_GREATER
166
+ Brotli ,
167
+ #endif
168
+ Deflate,
169
+ GZip ,
170
+ } ;
171
+
172
+ #if NET6_0_OR_GREATER
173
+ public const string Default = Brotli ;
174
+ #else
175
+ public const string Default = Deflate ;
176
+ #endif
177
+
178
+ public const string Brotli = "br" ;
179
+ public const string Deflate = "deflate" ;
180
+ public const string GZip = "gzip" ;
181
+
182
+ public static bool IsValid ( string compressionType )
183
+ {
184
+ #if NET6_0_OR_GREATER
185
+ return compressionType is Deflate or GZip or Brotli ;
186
+ #else
187
+ return compressionType is Deflate or GZip ;
188
+ #endif
189
+ }
190
+
191
+ public static void AssertIsValid ( string compressionType )
192
+ {
193
+ if ( ! IsValid ( compressionType ) )
194
+ {
195
+ throw new NotSupportedException ( compressionType
196
+ + " is not a supported compression type. Valid types: " + string . Join ( ", " , AllCompressionTypes ) ) ;
197
+ }
198
+ }
199
+
200
+ public static string GetExtension ( string compressionType )
201
+ {
202
+ switch ( compressionType )
203
+ {
204
+ case Brotli :
205
+ case Deflate :
206
+ case GZip :
207
+ return "." + compressionType ;
208
+ default :
209
+ throw new NotSupportedException (
210
+ "Unknown compressionType: " + compressionType ) ;
211
+ }
212
+ }
213
+ }
0 commit comments