Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 07f8c0f

Browse files
committed
Merge pull request #2386 from pgavlin/SystemNetRequests
Initial commit of System.Net.Requests
2 parents 1701015 + e5c85aa commit 07f8c0f

33 files changed

+6645
-93
lines changed
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
namespace System.Net
7+
{
8+
internal static partial class Interop
9+
{
10+
// WININET.DLL errors propagated as HRESULT's using FACILITY=WIN32
11+
// as returned by the WinRT Windows.Web.Http APIs. These HRESULT values
12+
// come from the Windows SDK winerror.h file. These values are set into
13+
// the Exception.HResult property.
14+
//
15+
// NOTE: Although .NET Core does not use wininet, .NET Native does and some
16+
// sources are shared between the two. Therefore although this may appear to
17+
// be dead code--note the lack of references to wininet elsewhere--it is not.
18+
19+
// No more Internet handles can be allocated
20+
public const int WININET_E_OUT_OF_HANDLES = unchecked((int)0x80072EE1);
21+
22+
// The operation timed out
23+
public const int WININET_E_TIMEOUT = unchecked((int)0x80072EE2);
24+
25+
// The server returned extended information
26+
public const int WININET_E_EXTENDED_ERROR = unchecked((int)0x80072EE3);
27+
28+
// An internal error occurred in the Microsoft Internet extensions
29+
public const int WININET_E_INTERNAL_ERROR = unchecked((int)0x80072EE4);
30+
31+
// The URL is invalid
32+
public const int WININET_E_INVALID_URL = unchecked((int)0x80072EE5);
33+
34+
// The URL does not use a recognized protocol
35+
public const int WININET_E_UNRECOGNIZED_SCHEME = unchecked((int)0x80072EE6);
36+
37+
// The server name or address could not be resolved
38+
public const int WININET_E_NAME_NOT_RESOLVED = unchecked((int)0x80072EE7);
39+
40+
// A protocol with the required capabilities was not found
41+
public const int WININET_E_PROTOCOL_NOT_FOUND = unchecked((int)0x80072EE8);
42+
43+
// The option is invalid
44+
public const int WININET_E_INVALID_OPTION = unchecked((int)0x80072EE9);
45+
46+
// The length is incorrect for the option type
47+
public const int WININET_E_BAD_OPTION_LENGTH = unchecked((int)0x80072EEA);
48+
49+
// The option value cannot be set
50+
public const int WININET_E_OPTION_NOT_SETTABLE = unchecked((int)0x80072EEB);
51+
52+
// Microsoft Internet Extension support has been shut down
53+
public const int WININET_E_SHUTDOWN = unchecked((int)0x80072EEC);
54+
55+
// The user name was not allowed
56+
public const int WININET_E_INCORRECT_USER_NAME = unchecked((int)0x80072EED);
57+
58+
// The password was not allowed
59+
public const int WININET_E_INCORRECT_PASSWORD = unchecked((int)0x80072EEE);
60+
61+
// The login request was denied
62+
public const int WININET_E_LOGIN_FAILURE = unchecked((int)0x80072EEF);
63+
64+
// The requested operation is invalid
65+
public const int WININET_E_INVALID_OPERATION = unchecked((int)0x80072EF0);
66+
67+
// The operation has been canceled
68+
public const int WININET_E_OPERATION_CANCELLED = unchecked((int)0x80072EF1);
69+
70+
// The supplied handle is the wrong type for the requested operation
71+
public const int WININET_E_INCORRECT_HANDLE_TYPE = unchecked((int)0x80072EF2);
72+
73+
// The handle is in the wrong state for the requested operation
74+
public const int WININET_E_INCORRECT_HANDLE_STATE = unchecked((int)0x80072EF3);
75+
76+
// The request cannot be made on a Proxy session
77+
public const int WININET_E_NOT_PROXY_REQUEST = unchecked((int)0x80072EF4);
78+
79+
// The registry value could not be found
80+
public const int WININET_E_REGISTRY_VALUE_NOT_FOUND = unchecked((int)0x80072EF5);
81+
82+
// The registry parameter is incorrect
83+
public const int WININET_E_BAD_REGISTRY_PARAMETER = unchecked((int)0x80072EF6);
84+
85+
// Direct Internet access is not available
86+
public const int WININET_E_NO_DIRECT_ACCESS = unchecked((int)0x80072EF7);
87+
88+
// No context value was supplied
89+
public const int WININET_E_NO_CONTEXT = unchecked((int)0x80072EF8);
90+
91+
// No status callback was supplied
92+
public const int WININET_E_NO_CALLBACK = unchecked((int)0x80072EF9);
93+
94+
// There are outstanding requests
95+
public const int WININET_E_REQUEST_PENDING = unchecked((int)0x80072EFA);
96+
97+
// The information format is incorrect
98+
public const int WININET_E_INCORRECT_FORMAT = unchecked((int)0x80072EFB);
99+
100+
// The requested item could not be found
101+
public const int WININET_E_ITEM_NOT_FOUND = unchecked((int)0x80072EFC);
102+
103+
// A connection with the server could not be established
104+
public const int WININET_E_CANNOT_CONNECT = unchecked((int)0x80072EFD);
105+
106+
// The connection with the server was terminated abnormally
107+
public const int WININET_E_CONNECTION_ABORTED = unchecked((int)0x80072EFE);
108+
109+
// The connection with the server was reset
110+
public const int WININET_E_CONNECTION_RESET = unchecked((int)0x80072EFF);
111+
112+
// The action must be retried
113+
public const int WININET_E_FORCE_RETRY = unchecked((int)0x80072F00);
114+
115+
// The proxy request is invalid
116+
public const int WININET_E_INVALID_PROXY_REQUEST = unchecked((int)0x80072F01);
117+
118+
// User interaction is required to complete the operation
119+
public const int WININET_E_NEED_UI = unchecked((int)0x80072F02);
120+
121+
// The handle already exists
122+
public const int WININET_E_HANDLE_EXISTS = unchecked((int)0x80072F04);
123+
124+
// The date in the certificate is invalid or has expired
125+
public const int WININET_E_SEC_CERT_DATE_INVALID = unchecked((int)0x80072F05);
126+
127+
// The host name in the certificate is invalid or does not match
128+
public const int WININET_E_SEC_CERT_CN_INVALID = unchecked((int)0x80072F06);
129+
130+
// A redirect request will change a non-secure to a secure connection
131+
public const int WININET_E_HTTP_TO_HTTPS_ON_REDIR = unchecked((int)0x80072F07);
132+
133+
// A redirect request will change a secure to a non-secure connection
134+
public const int WININET_E_HTTPS_TO_HTTP_ON_REDIR = unchecked((int)0x80072F08);
135+
136+
// Mixed secure and non-secure connections
137+
public const int WININET_E_MIXED_SECURITY = unchecked((int)0x80072F09);
138+
139+
// Changing to non-secure post
140+
public const int WININET_E_CHG_POST_IS_NON_SECURE = unchecked((int)0x80072F0A);
141+
142+
// Data is being posted on a non-secure connection
143+
public const int WININET_E_POST_IS_NON_SECURE = unchecked((int)0x80072F0B);
144+
145+
// A certificate is required to complete client authentication
146+
public const int WININET_E_CLIENT_AUTH_CERT_NEEDED = unchecked((int)0x80072F0C);
147+
148+
// The certificate authority is invalid or incorrect
149+
public const int WININET_E_INVALID_CA = unchecked((int)0x80072F0D);
150+
151+
// Client authentication has not been correctly installed
152+
public const int WININET_E_CLIENT_AUTH_NOT_SETUP = unchecked((int)0x80072F0E);
153+
154+
// An error has occurred in a Wininet asynchronous thread. You may need to restart
155+
public const int WININET_E_ASYNC_THREAD_FAILED = unchecked((int)0x80072F0F);
156+
157+
// The protocol scheme has changed during a redirect operaiton
158+
public const int WININET_E_REDIRECT_SCHEME_CHANGE = unchecked((int)0x80072F10);
159+
160+
// There are operations awaiting retry
161+
public const int WININET_E_DIALOG_PENDING = unchecked((int)0x80072F11);
162+
163+
// The operation must be retried
164+
public const int WININET_E_RETRY_DIALOG = unchecked((int)0x80072F12);
165+
166+
// There are no new cache containers
167+
public const int WININET_E_NO_NEW_CONTAINERS = unchecked((int)0x80072F13);
168+
169+
// A security zone check indicates the operation must be retried
170+
public const int WININET_E_HTTPS_HTTP_SUBMIT_REDIR = unchecked((int)0x80072F14);
171+
172+
// The SSL certificate contains errors.
173+
public const int WININET_E_SEC_CERT_ERRORS = unchecked((int)0x80072F17);
174+
175+
// It was not possible to connect to the revocation server or a definitive response could not be obtained.
176+
public const int WININET_E_SEC_CERT_REV_FAILED = unchecked((int)0x80072F19);
177+
178+
// The requested header was not found
179+
public const int WININET_E_HEADER_NOT_FOUND = unchecked((int)0x80072F76);
180+
181+
// The server does not support the requested protocol level
182+
public const int WININET_E_DOWNLEVEL_SERVER = unchecked((int)0x80072F77);
183+
184+
// The server returned an invalid or unrecognized response
185+
public const int WININET_E_INVALID_SERVER_RESPONSE = unchecked((int)0x80072F78);
186+
187+
// The supplied HTTP header is invalid
188+
public const int WININET_E_INVALID_HEADER = unchecked((int)0x80072F79);
189+
190+
// The request for a HTTP header is invalid
191+
public const int WININET_E_INVALID_QUERY_REQUEST = unchecked((int)0x80072F7A);
192+
193+
// The HTTP header already exists
194+
public const int WININET_E_HEADER_ALREADY_EXISTS = unchecked((int)0x80072F7B);
195+
196+
// The HTTP redirect request failed
197+
public const int WININET_E_REDIRECT_FAILED = unchecked((int)0x80072F7C);
198+
199+
// An error occurred in the secure channel support
200+
public const int WININET_E_SECURITY_CHANNEL_ERROR = unchecked((int)0x80072F7D);
201+
202+
// The file could not be written to the cache
203+
public const int WININET_E_UNABLE_TO_CACHE_FILE = unchecked((int)0x80072F7E);
204+
205+
// The TCP/IP protocol is not installed properly
206+
public const int WININET_E_TCPIP_NOT_INSTALLED = unchecked((int)0x80072F7F);
207+
208+
// The computer is disconnected from the network
209+
public const int WININET_E_DISCONNECTED = unchecked((int)0x80072F83);
210+
211+
// The server is unreachable
212+
public const int WININET_E_SERVER_UNREACHABLE = unchecked((int)0x80072F84);
213+
214+
// The proxy server is unreachable
215+
public const int WININET_E_PROXY_SERVER_UNREACHABLE = unchecked((int)0x80072F85);
216+
217+
// The proxy auto-configuration script is in error
218+
public const int WININET_E_BAD_AUTO_PROXY_SCRIPT = unchecked((int)0x80072F86);
219+
220+
// Could not download the proxy auto-configuration script file
221+
public const int WININET_E_UNABLE_TO_DOWNLOAD_SCRIPT = unchecked((int)0x80072F87);
222+
223+
// The supplied certificate is invalid
224+
public const int WININET_E_SEC_INVALID_CERT = unchecked((int)0x80072F89);
225+
226+
// The supplied certificate has been revoked
227+
public const int WININET_E_SEC_CERT_REVOKED = unchecked((int)0x80072F8A);
228+
229+
// The Dialup failed because file sharing was turned on and a failure was requested if security check was needed
230+
public const int WININET_E_FAILED_DUETOSECURITYCHECK = unchecked((int)0x80072F8B);
231+
232+
// Initialization of the WinINet API has not occurred
233+
public const int WININET_E_NOT_INITIALIZED = unchecked((int)0x80072F8C);
234+
235+
// Login failed and the client should display the entity body to the user
236+
public const int WININET_E_LOGIN_FAILURE_DISPLAY_ENTITY_BODY = unchecked((int)0x80072F8E);
237+
238+
// Content decoding has failed
239+
public const int WININET_E_DECODING_FAILED = unchecked((int)0x80072F8F);
240+
241+
// The HTTP request was not redirected
242+
public const int WININET_E_NOT_REDIRECTED = unchecked((int)0x80072F80);
243+
244+
// A cookie from the server must be confirmed by the user
245+
public const int WININET_E_COOKIE_NEEDS_CONFIRMATION = unchecked((int)0x80072F81);
246+
247+
// A cookie from the server has been declined acceptance
248+
public const int WININET_E_COOKIE_DECLINED = unchecked((int)0x80072F82);
249+
250+
// The HTTP redirect request must be confirmed by the user
251+
public const int WININET_E_REDIRECT_NEEDS_CONFIRMATION = unchecked((int)0x80072F88);
252+
}
253+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace System.Net
5+
{
6+
internal static class HttpValidationHelpers
7+
{
8+
// Returns true if stringValue contains characters that cannot appear
9+
// in a valid method-verb or HTTP header.
10+
public static bool IsInvalidMethodOrHeaderString(string stringValue)
11+
{
12+
for (int i = 0; i < stringValue.Length; i++)
13+
{
14+
switch (stringValue[i])
15+
{
16+
case '(':
17+
case ')':
18+
case '<':
19+
case '>':
20+
case '@':
21+
case ',':
22+
case ';':
23+
case ':':
24+
case '\\':
25+
case '"':
26+
case '\'':
27+
case '/':
28+
case '[':
29+
case ']':
30+
case '?':
31+
case '=':
32+
case '{':
33+
case '}':
34+
case ' ':
35+
case '\t':
36+
case '\r':
37+
case '\n':
38+
return true;
39+
40+
default:
41+
break;
42+
}
43+
}
44+
45+
return false;
46+
}
47+
}
48+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
namespace System.Net.Tests
7+
{
8+
internal class HttpTestServers
9+
{
10+
// Issue 2383: Figure out how to provide parameters to unit tests at build/run-time.
11+
//
12+
// It would be very nice if the server to used for testing was configurable at build/run-time
13+
// in order to avoid a strict dependency on network access when running tests.
14+
public const string Host = "httpbin.org";
15+
16+
public readonly static Uri RemoteGetServer = new Uri("http://" + Host + "/get");
17+
public readonly static Uri RemotePostServer = new Uri("http://" + Host + "/post");
18+
public readonly static Uri SecureRemoteGetServer = new Uri("https://" + Host + "/get");
19+
public readonly static Uri SecureRemotePostServer = new Uri("https://" + Host + "/post");
20+
21+
public const string RemoteStatusCodeServerFormat = "http://" + Host + "/status/{0}";
22+
public const string SecureRemoteStatusCodeServerFormat = "https://" + Host + "/status/{0}";
23+
24+
public readonly static object[][] GetServers = { new object[] { RemoteGetServer }, new object[] { SecureRemoteGetServer } };
25+
public readonly static object[][] PostServers = { new object[] { RemotePostServer }, new object[] { SecureRemotePostServer } };
26+
}
27+
}

0 commit comments

Comments
 (0)