1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Net.Http.Headers;
namespace System.Net.Http
{
internal static class ParserData
{
public const int MinHeaderSize = 2;
public const int MinMessageSize = 10;
public const int MinRequestLineSize = 14;
public const int MinStatusLineSize = 15;
public const int MinBufferSize = 256;
public static IEnumerable<object[]> Boundaries
{
get
{
yield return new object[] { "1" };
yield return new object[] { "a" };
yield return new object[] { "'" };
yield return new object[] { "(" };
yield return new object[] { ")" };
yield return new object[] { "+" };
yield return new object[] { "_" };
yield return new object[] { "-" };
yield return new object[] { "." };
yield return new object[] { "/" };
yield return new object[] { ":" };
yield return new object[] { "=" };
yield return new object[] { "?" };
yield return new object[] { "--" };
yield return new object[] { "--------------------01234567890123456789" };
yield return new object[] { "--------------------01234567890123456789--------------------" };
yield return new object[] { "--A--B--C--D--E--F--" };
}
}
public static IEnumerable<object[]> Versions
{
get
{
yield return new object[] { Version.Parse("1.0") };
yield return new object[] { Version.Parse("1.1") };
yield return new object[] { Version.Parse("1.2") };
yield return new object[] { Version.Parse("2.0") };
yield return new object[] { Version.Parse("10.0") };
yield return new object[] { Version.Parse("1.15") };
}
}
public static IEnumerable<object[]> InvalidVersions
{
get
{
yield return new object[] { "" };
yield return new object[] { "http/1.1" };
yield return new object[] { "HTTP/a.1" };
yield return new object[] { "HTTP/1.a" };
yield return new object[] { "HTTP 1.1" };
yield return new object[] { "HTTP\t1.1" };
yield return new object[] { "HTTP 1 1" };
yield return new object[] { "\0" };
yield return new object[] { "HTTP\01.1" };
yield return new object[] { "HTTP/4294967295.4294967295" };
}
}
public static readonly string[] InvalidMethods = new string[]
{
"",
"G\tT",
"G E T",
"\0",
"G\0T",
"GET\n",
};
public static readonly string[] InvalidReasonPhrases = new string[]
{
"\0",
"\t",
"reason\n",
};
// This deliberately only checks for syntac boundaries of the URI, not its content
public static readonly string[] InvalidRequestUris = new string[]
{
"",
"p a t h",
"path ",
" path ",
};
public static readonly string[] InvalidStatusCodes = new string[]
{
"0",
"99",
"1a1",
"abc",
"1001",
"2000",
Int32.MinValue.ToString(),
Int32.MaxValue.ToString(),
};
public static readonly Dictionary<string, string> ValidHeaders = new Dictionary<string, string>
{
{ "N0", "V0"},
{ "N1", "V1"},
{ "N2", "V2"},
{ "N3", "V3"},
{ "N4", "V4"},
{ "N5", "V5"},
{ "N6", "V6"},
{ "N7", "V7"},
{ "N8", "V8"},
{ "N9", "V9"},
};
public static readonly string HttpMethod = "TEG";
public static readonly HttpStatusCode HttpStatus = HttpStatusCode.Created;
public static readonly string HttpReasonPhrase = "ReasonPhrase";
public static readonly string HttpHostName = "example.com";
public static readonly int HttpHostPort = 1234;
public static readonly string HttpMessageEntity = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
public static readonly Uri HttpRequestUri = new Uri("http://" + HttpHostName + "/some/path");
public static readonly Uri HttpRequestUriWithPortAndQuery = new Uri("http://" + HttpHostName + ":" + HttpHostPort + "/some/path?%C3%A6%C3%B8%C3%A5");
public static readonly Uri HttpsRequestUri = new Uri("https://" + HttpHostName + "/some/path");
public static readonly string HttpRequest =
HttpMethod +
" /some/path HTTP/1.2\r\nHost: " +
HttpHostName +
"\r\nN1: V1a, V1b, V1c, V1d, V1e\r\nN2: V2\r\n\r\n";
public static readonly string HttpRequestWithHost =
HttpMethod +
" /some/path HTTP/1.2\r\n" +
"N1: V1a, V1b, V1c, V1d, V1e\r\nN2: V2\r\nHost: " +
HttpHostName + "\r\n\r\n";
public static readonly string HttpRequestWithPortAndQuery =
HttpMethod +
" /some/path?%C3%A6%C3%B8%C3%A5 HTTP/1.2\r\nHost: " +
HttpHostName + ":" + HttpHostPort.ToString() +
"\r\nN1: V1a, V1b, V1c, V1d, V1e\r\nN2: V2\r\n\r\n";
public static readonly string HttpResponse =
"HTTP/1.2 " +
((int)HttpStatus).ToString() +
" " +
HttpReasonPhrase +
"\r\nN1: V1a, V1b, V1c, V1d, V1e\r\nN2: V2\r\n\r\n";
public static readonly string TextContentType = "text/plain; charset=utf-8";
public static readonly string HttpRequestWithEntity =
HttpMethod +
" /some/path HTTP/1.2\r\nHost: " +
HttpHostName +
"\r\nN1: V1a, V1b, V1c, V1d, V1e\r\nN2: V2\r\nContent-Type: " +
TextContentType +
"\r\n\r\n" +
HttpMessageEntity;
public static readonly string HttpResponseWithEntity =
"HTTP/1.2 " +
((int)HttpStatus).ToString() +
" " +
HttpReasonPhrase +
"\r\nN1: V1a, V1b, V1c, V1d, V1e\r\nN2: V2\r\nContent-Type: " +
TextContentType +
"\r\n\r\n" +
HttpMessageEntity;
public static readonly MediaTypeHeaderValue HttpRequestMediaType;
public static readonly MediaTypeHeaderValue HttpResponseMediaType;
static ParserData()
{
MediaTypeHeaderValue.TryParse("application/http; msgtype=request", out HttpRequestMediaType);
MediaTypeHeaderValue.TryParse("application/http; msgtype=response", out HttpResponseMediaType);
}
}
}
|