コード例 #1
0
        public virtual void ShapeHttpResponse(HttpWebResponse rightSideResponse, HttpResponse leftSideResponse)
        {
            HeaderTransformer headerTransformer =
                new HeaderTransformer(rightSideResponse, leftSideResponse, RootUrl, RemoteApplicationProxyPath, IsolateCookies);

            headerTransformer.Transform();
            leftSideResponse.StatusCode        = (int)rightSideResponse.StatusCode;
            leftSideResponse.ContentType       = rightSideResponse.ContentType;
            leftSideResponse.StatusDescription = rightSideResponse.StatusDescription;
        }
コード例 #2
0
        public virtual HttpWebRequest CreateRightSideRequest(Stream inputBuffer)
        {
            _rightSideRequest = (HttpWebRequest)HttpWebRequest.Create(_application.GetRightSideUrl(_leftSideRequest));

            _rightSideRequest.AllowAutoRedirect = false;
            _rightSideRequest.Timeout           = Settings.Default.RequestTimeoutSeconds * 1000;

            _rightSideRequest.CookieContainer = new CookieContainer();

            if (_application.Certificate != null)
            {
                _rightSideRequest.ClientCertificates.Add(_application.Certificate);
            }

            if (!_application.ByPass(_leftSideRequest.Url.AbsolutePath))
            {
                AuthorizationWebServiceProxy authorizationProxy =
                    new AuthorizationWebServiceProxy(_application.Directory.AuthorizationWebService);
                string userName = _auth.UserId;
                _authorization = authorizationProxy.GetAuthorization(_application.RootUrl, userName);

                if (!Properties.Settings.Default.ProcessRequestWithoutAuthorization)
                {
                    if (_authorization == null || _authorization == CustomAuthorization.NoAuthorization)
                    {
                        throw new AuthorizationException("No Authorization received.");
                    }
                }
            }
            HeaderTransformer headerTransformer = new HeaderTransformer(_leftSideRequest,
                                                                        _rightSideRequest,
                                                                        IsSoap ? PvpTokenHandling.remove : _application.PvpInformationHandling,
                                                                        _application.RootUrl,
                                                                        _application.RemoteApplicationProxyPath,
                                                                        _application.IsolateCookies,
                                                                        _authorization == null ? null : _authorization.PvpVersion);

            headerTransformer.Transform();

            Dictionary <PvpAttributes, string> headersNames = null;

            if (_authorization != null && _authorization.PvpVersion == PvpVersionNumber.Version19)
            {
                headersNames = s_ProxyHeaderNames19;
            }

            if (_authorization != null && (_authorization.PvpVersion == PvpVersionNumber.Version20 || _authorization.PvpVersion == PvpVersionNumber.Version21))
            {
                headersNames = s_ProxyHeaderNames20;
            }

            if (!IsSoap && headersNames != null)
            {
                _rightSideRequest.Headers.Add(headersNames[PvpAttributes.ORIG_SCHEME], _leftSideRequest.Url.Scheme);
                int    port       = _leftSideRequest.Url.Port;
                string portString = (port == 80 || port == 443) ? String.Empty : ":" + port.ToString();
                _rightSideRequest.Headers.Add(headersNames[PvpAttributes.ORIG_HOST], _leftSideRequest.Url.Host + portString);
                _rightSideRequest.Headers.Add(headersNames[PvpAttributes.ORIG_URI], _leftSideRequest.Url.AbsolutePath);
            }

            if (headersNames != null && String.IsNullOrEmpty(_leftSideRequest.Headers[headersNames[PvpAttributes.TXID]]))
            {
                _rightSideRequest.Headers.Add(headersNames[PvpAttributes.TXID], GetTxId());
            }

            _rightSideRequest.Method = _leftSideRequest.HttpMethod;

            _rightSideRequest.AuthenticationLevel =
                Egora.Stammportal.HttpReverseProxy.Properties.Settings.Default.AuthenticationLevel;
            _rightSideRequest.UseDefaultCredentials = true;
            if (_rightSideRequest.Proxy != null)
            {
                _rightSideRequest.Proxy.Credentials = CredentialCache.DefaultCredentials;
            }
            _rightSideRequest.PreAuthenticate = true;

            if (_authorization != null && _authorization.HttpHeaders != null &&
                _authorization != CustomAuthorization.NoAuthorization)
            {
                foreach (HttpHeader header in _authorization.HttpHeaders)
                {
                    if (header != null)
                    {
                        _rightSideRequest.Headers.Add(header.Name, header.Value);
                    }
                }
            }

            HandleRequestContent(inputBuffer);

            return(_rightSideRequest);
        }