Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 73fedf1

Browse files
committed
Refactor HttpUtils into different classes to prepare for alt net6 impl
1 parent 296c7a8 commit 73fedf1

File tree

6 files changed

+2098
-2084
lines changed

6 files changed

+2098
-2084
lines changed

src/ServiceStack.Text/Env.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,16 @@ static Env()
104104
VersionString = ServiceStackVersion.ToString(CultureInfo.InvariantCulture);
105105

106106
ServerUserAgent = "ServiceStack/"
107-
+ VersionString + " "
108-
+ PclExport.Instance.PlatformName
109-
+ (IsMono ? "/Mono" : "")
110-
+ (IsLinux ? "/Linux" : IsOSX ? "/OSX" : IsUnix ? "/Unix" : IsWindows ? "/Windows" : "/UnknownOS")
111-
+ (IsIOS ? "/iOS" : IsAndroid ? "/Android" : IsUWP ? "/UWP" : "")
112-
+ (IsNet6 ? "/net6" : IsNetStandard20 ? "/std2.0" : IsNetFramework ? "netfx" : "")
113-
+ ($"/{LicenseUtils.Info}");
114-
107+
+ VersionString + " "
108+
+ PclExport.Instance.PlatformName
109+
+ (IsLinux ? "/Linux" : IsOSX ? "/OSX" : IsUnix ? "/Unix" : IsWindows ? "/Windows" : "/UnknownOS") + (IsIOS ? "/iOS" : IsAndroid ? "/Android" : IsUWP ? "/UWP" : "")
110+
+ PlatformModifier
111+
+ $"/{LicenseUtils.Info}";
115112
__releaseDate = new DateTime(2001,01,01);
116113
}
117114

115+
public static string PlatformModifier => (IsNet6 ? "/net6" : IsNetStandard20 ? "/std2.0" : IsNetFramework ? "/netfx" : "") + (IsMono ? "/Mono" : "");
116+
118117
public static string VersionString { get; set; }
119118

120119
public static decimal ServiceStackVersion = 6.01m;

src/ServiceStack.Text/HttpHeaders.cs

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
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+
}

src/ServiceStack.Text/HttpMethods.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
3+
namespace ServiceStack;
4+
5+
public static class HttpMethods
6+
{
7+
static readonly string[] allVerbs = {
8+
"OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT", // RFC 2616
9+
"PROPFIND", "PROPPATCH", "MKCOL", "COPY", "MOVE", "LOCK", "UNLOCK", // RFC 2518
10+
"VERSION-CONTROL", "REPORT", "CHECKOUT", "CHECKIN", "UNCHECKOUT",
11+
"MKWORKSPACE", "UPDATE", "LABEL", "MERGE", "BASELINE-CONTROL", "MKACTIVITY", // RFC 3253
12+
"ORDERPATCH", // RFC 3648
13+
"ACL", // RFC 3744
14+
"PATCH", // https://datatracker.ietf.org/doc/draft-dusseault-http-patch/
15+
"SEARCH", // https://datatracker.ietf.org/doc/draft-reschke-webdav-search/
16+
"BCOPY", "BDELETE", "BMOVE", "BPROPFIND", "BPROPPATCH", "NOTIFY",
17+
"POLL", "SUBSCRIBE", "UNSUBSCRIBE" //MS Exchange WebDav: http://msdn.microsoft.com/en-us/library/aa142917.aspx
18+
};
19+
20+
public static HashSet<string> AllVerbs = new(allVerbs);
21+
22+
public static bool Exists(string httpMethod) => AllVerbs.Contains(httpMethod.ToUpper());
23+
public static bool HasVerb(string httpVerb) => Exists(httpVerb);
24+
25+
public const string Get = "GET";
26+
public const string Put = "PUT";
27+
public const string Post = "POST";
28+
public const string Delete = "DELETE";
29+
public const string Options = "OPTIONS";
30+
public const string Head = "HEAD";
31+
public const string Patch = "PATCH";
32+
}

0 commit comments

Comments
 (0)