Example #1
0
 public static partial bool WinHttpQueryHeaders(
     SafeWinHttpHandle requestHandle,
     uint infoLevel,
     string name,
     ref uint number,
     ref uint bufferLength,
     IntPtr index);
Example #2
0
        public static extern bool WinHttpAddRequestHeaders(
            SafeWinHttpHandle requestHandle,
#pragma warning disable CA1838 // Uses pooled StringBuilder
            [In] StringBuilder headers,
#pragma warning restore CA1838
            uint headersLength,
            uint modifiers);
Example #3
0
 public static partial bool WinHttpSetCredentials(
     SafeWinHttpHandle requestHandle,
     uint authTargets,
     uint authScheme,
     string? userName,
     string? password,
     IntPtr reserved);
 public static extern bool WinHttpQueryHeaders(
     SafeWinHttpHandle requestHandle,
     uint infoLevel,
     string name,
     [Out] StringBuilder buffer,
     ref uint bufferLength,
     ref uint index);
Example #5
0
 public static extern bool WinHttpSendRequest(
     SafeWinHttpHandle requestHandle,
     [In] StringBuilder headers,
     uint headersLength,
     IntPtr optional,
     uint optionalLength,
     uint totalLength,
     IntPtr context);
 public static void DisposeAndClearHandle(ref SafeWinHttpHandle handle)
 {
     if (handle != null)
     {
         handle.Dispose();
         handle = null;
     }
 }
 public static extern SafeWinHttpHandle WinHttpOpenRequest(
     SafeWinHttpHandle connectHandle,
     string verb,
     string objectName,
     string version,
     string referrer,
     string acceptTypes,
     uint flags);
 public static void DisposeAndClearHandle(ref SafeWinHttpHandle safeHandle)
 {
     if (safeHandle != null)
     {
         safeHandle.Dispose();
         safeHandle = null;
     }
 }
Example #9
0
        public static extern bool WinHttpQueryHeaders(
#endif
            SafeWinHttpHandle requestHandle,
            uint infoLevel,
            string name,
            IntPtr buffer,
            ref uint bufferLength,
            ref uint index);
Example #10
0
 public static void DisposeAndClearHandle(ref SafeWinHttpHandle winHttpHandler)
 {
     if (winHttpHandler != null)
     {
         winHttpHandler.Dispose();
         winHttpHandler = null;
     }
 }
Example #11
0
 public static partial bool WinHttpSendRequest(
     SafeWinHttpHandle requestHandle,
     IntPtr headers,
     uint headersLength,
     IntPtr optional,
     uint optionalLength,
     uint totalLength,
     IntPtr context);
Example #12
0
 public static extern SafeWinHttpHandleWithCallback WinHttpOpenRequestWithCallback(
     SafeWinHttpHandle connectHandle,
     string verb,
     string objectName,
     string version,
     string referrer,
     string acceptTypes,
     uint flags);
Example #13
0
 public static extern bool WinHttpSendRequest(
     SafeWinHttpHandle requestHandle,
     [In] StringBuilder headers,
     uint headersLength,
     IntPtr optional,
     uint optionalLength,
     uint totalLength,
     IntPtr context);
 public static void DisposeAndClearHandle(ref SafeWinHttpHandle handle)
 {
     if (handle != null)
     {
         handle.Dispose();
         handle = null;
     }
 }
 public static void DisposeAndClearHandle(ref SafeWinHttpHandle safeHandle)
 {
     if (safeHandle != null)
     {
         safeHandle.Dispose();
         safeHandle = null;
     }
 }
Example #16
0
            // Important: WinHttp API calls should not happen while another WinHttp call for the same handle did not
            // return. During finalization that was not initiated by the Dispose pattern we don't expect any other WinHttp
            // calls in progress.
            protected override bool ReleaseHandle()
            {
                if (_parentHandle != null)
                {
                    _parentHandle.DangerousRelease();
                    _parentHandle = null;
                }

                return(Interop.WinHttp.WinHttpCloseHandle(handle));
            }
            // Important: WinHttp API calls should not happen while another WinHttp call for the same handle did not
            // return. During finalization that was not initiated by the Dispose pattern we don't expect any other WinHttp
            // calls in progress.
            protected override bool ReleaseHandle()
            {
                if (_parentHandle != null)
                {
                    _parentHandle.DangerousRelease();
                    _parentHandle = null;
                }

                // TODO(Issue 2500): Add logging so we know when the handle gets closed.
                return(Interop.WinHttp.WinHttpCloseHandle(handle));
            }
 // Important: WinHttp API calls should not happen while another WinHttp call for the same handle did not 
 // return. During finalization that was not initiated by the Dispose pattern we don't expect any other WinHttp
 // calls in progress.
 protected override bool ReleaseHandle()
 {
     if (_parentHandle != null)
     {
         _parentHandle.DangerousRelease();
         _parentHandle = null;
     }
     
     // TODO(Issue 2500): Add logging so we know when the handle gets closed.
     return Interop.WinHttp.WinHttpCloseHandle(handle);
 }
            public void SetParentHandle(SafeWinHttpHandle parentHandle)
            {
                Debug.Assert(_parentHandle == null);
                Debug.Assert(parentHandle != null);
                Debug.Assert(!parentHandle.IsInvalid);

                bool ignore = false;
                parentHandle.DangerousAddRef(ref ignore);
                
                _parentHandle = parentHandle;
            }
            public void SetParentHandle(SafeWinHttpHandle parentHandle)
            {
                Debug.Assert(_parentHandle == null);
                Debug.Assert(parentHandle != null);
                Debug.Assert(!parentHandle.IsInvalid);

                bool ignore = false;

                parentHandle.DangerousAddRef(ref ignore);

                _parentHandle = parentHandle;
            }
Example #21
0
        private uint CalculateHeaderBufferSize(SafeWinHttpHandle hRequest)
        {
            uint bufferLengthInBytes = 0;
            uint index = 0;

            if (!WinHttpQueryHeaders(
                    hRequest,
                    WINHTTP_QUERY_RAW_HEADERS_CRLF,
                    WINHTTP_HEADER_NAME_BY_INDEX,
                    IntPtr.Zero,
                    ref bufferLengthInBytes,
                    ref index) && Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER)
            {
                return(bufferLengthInBytes);
            }
            return(0);
        }
Example #22
0
        private string GetHeaders(SafeWinHttpHandle hRequest, uint bufferLengthInBytes)
        {
            uint index = 0;
            var  pBuf  = Marshal.AllocHGlobal((int)bufferLengthInBytes);

            if (!WinHttpQueryHeaders(
                    hRequest,
                    WINHTTP_QUERY_RAW_HEADERS_CRLF,
                    WINHTTP_HEADER_NAME_BY_INDEX,
                    pBuf,
                    ref bufferLengthInBytes,
                    ref index))
            {
                throw new IOException("Unable to read headers: " + Marshal.GetLastWin32Error());
            }
            Log.Debug("Header len after read: " + bufferLengthInBytes);
            var header = Marshal.PtrToStringAuto(pBuf);

            Marshal.FreeHGlobal(pBuf);
            return(header);
        }
Example #23
0
        public WinHttpSession(
            Uri responseUri,
            SafeWinHttpHandle hConnect,
            SafeWinHttpHandle hRequest,
            Dictionary <string, List <string> >?headers,
            Dictionary <string, string>?cookies,
            byte[]?postData = null)
        {
            this.responseUri = responseUri;
            this.hConnect    = hConnect;
            this.hRequest    = hRequest;
            this.callback    = new(WinHttpCallback);
            IntPtr oldCallback = WinHttpSetStatusCallback(
                hRequest,
                this.callback,
                WINHTTP_CALLBACK_FLAG_REDIRECT,
                IntPtr.Zero);

            if (oldCallback == new IntPtr(WINHTTP_INVALID_STATUS_CALLBACK))
            {
                int lastError = Marshal.GetLastWin32Error();
                if (lastError != ERROR_INVALID_HANDLE) // Ignore error if handle was already closed.
                {
                    throw new IOException(nameof(WinHttpSetStatusCallback));
                }
            }
            this.headers = headers;
            this.cookies = cookies;
            if (postData != null && postData.Length > 0)
            {
                this.postData = Marshal.AllocHGlobal(postData.Length);
                Marshal.Copy(postData, 0, this.postData.Value, postData.Length);
                this.postDataSize = postData.Length;
            }
            this.responseStream = new WinHttpResponseStream(this.hRequest);
        }
Example #24
0
 public static extern SafeWinHttpHandleWithCallback WinHttpConnectWithCallback(
     SafeWinHttpHandle sessionHandle,
     string serverName,
     ushort serverPort,
     uint reserved);
Example #25
0
 public static extern bool WinHttpQueryOption(
     SafeWinHttpHandle handle,
     uint option,
     IntPtr buffer,
     ref uint bufferSize);
Example #26
0
 public static extern uint WinHttpWebSocketClose(
     SafeWinHttpHandle webSocketHandle,
     ushort status,
     IntPtr reason,
     uint reasonLength);
Example #27
0
 public static extern uint WinHttpWebSocketQueryCloseStatus(
     SafeWinHttpHandle webSocketHandle,
     out ushort status,
     byte[] reason,
     uint reasonLength,
     out uint reasonLengthConsumed);
Example #28
0
 public static extern bool WinHttpSetOption(
     SafeWinHttpHandle handle,
     uint option,
     IntPtr optionData,
     uint optionLength);
Example #29
0
 public static extern uint WinHttpWebSocketShutdown(
     SafeWinHttpHandle webSocketHandle,
     ushort status,
     byte[] reason,
     uint reasonLength);
Example #30
0
 public static extern bool WinHttpWriteData(
     SafeWinHttpHandle requestHandle,
     IntPtr buffer,
     uint bufferSize,
     IntPtr parameterIgnoredAndShouldBeNullForAsync);
Example #31
0
 public static extern bool WinHttpReceiveResponse(
     SafeWinHttpHandle requestHandle,
     IntPtr reserved);
Example #32
0
 public static extern bool WinHttpReadData(
     SafeWinHttpHandle requestHandle,
     IntPtr buffer,
     uint bufferSize,
     out uint bytesRead);
Example #33
0
 public static extern bool WinHttpQueryDataAvailable(
     SafeWinHttpHandle requestHandle,
     IntPtr parameterIgnoredAndShouldBeNullForAsync);
Example #34
0
 public static extern bool WinHttpQueryHeaders(
     SafeWinHttpHandle requestHandle,
     uint infoLevel,
     string name,
     [Out] StringBuilder buffer,
     ref uint bufferLength,
     ref uint index);
Example #35
0
 public static extern IntPtr WinHttpSetStatusCallback(
     SafeWinHttpHandle handle,
     WINHTTP_STATUS_CALLBACK callback,
     uint notificationFlags,
     IntPtr reserved);
Example #36
0
 public static extern bool WinHttpSetTimeouts(
     SafeWinHttpHandle handle,
     int resolveTimeout,
     int connectTimeout,
     int sendTimeout,
     int receiveTimeout);
Example #37
0
 public static extern bool WinHttpAddRequestHeaders(
     SafeWinHttpHandle requestHandle,
     string headers,
     uint headersLength,
     uint modifiers);
Example #38
0
 public static extern bool WinHttpWriteData(
     SafeWinHttpHandle requestHandle,
     IntPtr buffer,
     uint bufferSize,
     out uint bytesWritten);
Example #39
0
 public static extern bool WinHttpQueryDataAvailable(
     SafeWinHttpHandle requestHandle,
     out uint bytesAvailable);
Example #40
0
 public static extern bool WinHttpQueryOption(
     SafeWinHttpHandle handle,
     uint option,
     [Out] StringBuilder buffer,
     ref uint bufferSize);
Example #41
0
 public static extern bool WinHttpQueryDataAvailable(
     SafeWinHttpHandle requestHandle,
     out uint bytesAvailable);
Example #42
0
 public static extern bool WinHttpQueryOption(
     SafeWinHttpHandle handle,
     uint option,
     ref uint buffer,
     ref uint bufferSize);
Example #43
0
 public static extern uint WinHttpWebSocketSend(
     SafeWinHttpHandle webSocketHandle,
     WINHTTP_WEB_SOCKET_BUFFER_TYPE bufferType,
     IntPtr buffer,
     uint bufferLength);
Example #44
0
 public static extern uint WinHttpWebSocketReceive(
     SafeWinHttpHandle webSocketHandle,
     IntPtr buffer,
     uint bufferLength,
     out uint bytesRead,
     out WINHTTP_WEB_SOCKET_BUFFER_TYPE bufferType);
Example #45
0
 public static extern bool WinHttpSetOption(
     SafeWinHttpHandle handle,
     uint option,
     ref uint optionData,
     uint optionLength = sizeof(uint));
Example #46
0
 public static extern bool WinHttpQueryHeaders(
     SafeWinHttpHandle requestHandle,
     uint infoLevel,
     string name,
     ref uint number,
     ref uint bufferLength,
     IntPtr index);
Example #47
0
 public static extern bool WinHttpSetOption(
     SafeWinHttpHandle handle,
     uint option,
     ref uint optionData,
     uint optionLength = sizeof(uint));
Example #48
0
 public static extern bool WinHttpSetOption(
     SafeWinHttpHandle handle,
     uint option,
     IntPtr optionData,
     uint optionLength);
Example #49
0
 public static extern bool WinHttpQueryAuthSchemes(
     SafeWinHttpHandle requestHandle,
     out uint supportedSchemes,
     out uint firstScheme,
     out uint authTarget);
Example #50
0
 public static extern bool WinHttpSetCredentials(
     SafeWinHttpHandle requestHandle,
     uint authTargets,
     uint authScheme,
     string userName,
     string password,
     IntPtr reserved);
Example #51
0
 public static extern bool WinHttpGetProxyForUrl(
     SafeWinHttpHandle sessionHandle, string url,
     ref WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions,
     out WINHTTP_PROXY_INFO proxyInfo);
Example #52
0
 public static extern bool WinHttpQueryAuthSchemes(
     SafeWinHttpHandle requestHandle,
     out uint supportedSchemes,
     out uint firstScheme,
     out uint authTarget);
Example #53
0
 public static extern SafeWinHttpHandle WinHttpConnect(
     SafeWinHttpHandle sessionHandle,
     string serverName,
     ushort serverPort,
     uint reserved);
Example #54
0
 public static extern bool WinHttpSetTimeouts(
     SafeWinHttpHandle handle,
     int resolveTimeout,
     int connectTimeout,
     int sendTimeout,
     int receiveTimeout);
Example #55
0
 public static extern bool WinHttpAddRequestHeaders(
     SafeWinHttpHandle requestHandle,
     string headers,
     uint headersLength,
     uint modifiers);
Example #56
0
 public static extern bool WinHttpGetProxyForUrl(
     SafeWinHttpHandle sessionHandle, string url,
     ref WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions,
     out WINHTTP_PROXY_INFO proxyInfo);
Example #57
0
 public static extern bool WinHttpReceiveResponse(
     SafeWinHttpHandle requestHandle,
     IntPtr reserved);
Example #58
0
 public static extern IntPtr WinHttpSetStatusCallback(
     SafeWinHttpHandle handle,
     WINHTTP_STATUS_CALLBACK callback,
     uint notificationFlags,
     IntPtr reserved);
Example #59
0
 public static extern bool WinHttpReadData(
     SafeWinHttpHandle requestHandle,
     IntPtr buffer,
     uint bufferSize,
     IntPtr parameterIgnoredAndShouldBeNullForAsync);
Example #60
0
 public static extern SafeWinHttpHandleWithCallback WinHttpWebSocketCompleteUpgrade(
     SafeWinHttpHandle requestHandle,
     IntPtr context);