■ ■ ■ ■ ■ ■
Src/ES.Taipan.Infrastructure/Network/DefaultHttpRequestor.fs
skipped 18 lines 19 19 20 20 type DefaultHttpRequestor(defaultSettings: HttpRequestorSettings, logProvider: ILogProvider) as this = 21 21 let _requestGateTimeout = 1000 * 60 * 60 * 10 // 10 minutes 22 + let _authenticationLock = new Object() 22 23 let _maxParallelism = 100 23 24 let _requestGate = new RequestGate(_maxParallelism) 24 25 let _certificationValidate = new Event<CertificationValidateEventArgs>() skipped 23 lines 48 49 let headerName = kv.Key 49 50 let headerValue = kv.Value 50 51 let headerAlredyPresent = 51 - httpRequest.Headers | > Seq . toList 52 + httpRequest.Headers 53 + |> Seq.toList 52 54 |> List.exists (fun hdr -> hdr.Name.Equals(headerName, StringComparison.Ordinal)) 53 55 if not headerAlredyPresent then 54 - httpRequest.Headers.Add(new HttpHeader(Name=headerName, Value=headerValue)) 56 + if headerName.Equals("cookie", StringComparison.OrdinalIgnoreCase) then 57 + httpRequest.Cookies.AddRange(HttpUtility.parseCookieHeaderValue(headerValue, httpRequest.Uri.Host)) 58 + else 59 + httpRequest.Headers.Add(new HttpHeader(Name=headerName, Value=headerValue)) 55 60 56 61 // add cookies 57 62 for kv in _settings.AdditionalCookies do skipped 65 lines 123 128 match _seleniumDriver with 124 129 | Some _ -> () 125 130 | None -> 131 + if _settings.ProxyUrl.IsSome then 132 + let proxyUri = new Uri(_settings.ProxyUrl.Value) 133 + _seleniumDriver.Value.ProxyUrl <- Some(String.Format("{0}:{1}", proxyUri.Host, proxyUri.Port)) 134 + 126 135 _seleniumDriver <- Some(new SeleniumDriver(logProvider)) 127 - _seleniumDriver.Value.ProxyUrl <- _settings.ProxyUrl 128 136 _seleniumDriver.Value.Initialize() 129 137 ) 130 138 skipped 4 lines 135 143 let rec sendJourneyTransaction (path: JourneyPath) (transaction: JourneyTransaction) : HttpResponse option = 136 144 let httpRequest = transaction.BuildBaseHttpRequest() 137 145 138 - // add to setting also the headers of the template request 139 - httpRequest.Headers 140 - |> Seq.filter(fun hdr -> 141 - ["Content"] 142 - |> List.exists(fun pattern -> hdr.Name.StartsWith(pattern, StringComparison.OrdinalIgnoreCase)) 143 - |> not 144 - ) 145 - |> Seq.iter(fun hdr -> _settings.AdditionalHttpHeaders.[hdr.Name] <- hdr.Value) 146 - 147 146 // manage parameters 148 147 let data = new StringBuilder() 149 148 let query = new StringBuilder() skipped 34 lines 184 183 this.SessionState.Value.RetrieveSessionParametersFromResponse(httpRequest, httpResponse.Value) 185 184 186 185 httpResponse 186 + 187 + let isStatusCodeValidForauthenticationCheck(httpResponse: HttpResponse option) = 188 + match httpResponse with 189 + | None -> false 190 + | Some _ -> 191 + let sc = int httpResponse.Value.StatusCode 192 + sc >= 200 && sc < 400 187 193 188 194 let followPathNavigation() = 189 195 match _settings.Journey.Paths |> Seq.tryHead with skipped 201 lines 391 397 httpResponse.Headers 392 398 |> Seq.filter(fun hdr -> hdr.Name.Equals("set-cookie", StringComparison.Ordinal)) 393 399 |> Seq.iter(fun hdr -> 394 - let cookies = HttpRequestorUtility .parseCookieHeaderValue(hdr.Value, httpResponse.ResponseUri.Value.Host) 400 + let cookies = HttpUtility .parseCookieHeaderValue(hdr.Value, httpResponse.ResponseUri.Value.Host) 395 401 this.SessionState.Value.AddCookieToSession(httpRequest, cookies) 396 402 ) 397 403 skipped 16 lines 414 420 415 421 member private this.VerifyIfIsNeededToAuthenticate(httpRequest: HttpRequest, httpResponse: HttpResponse option) = 416 422 if not _skipAuthenticationProcess && _settings.Authentication.Enabled then 417 - let savedValue = _skipAuthenticationProcess 418 - _skipAuthenticationProcess <- true 423 + lock _authenticationLock (fun () -> 424 + let savedValue = _skipAuthenticationProcess 425 + _skipAuthenticationProcess <- true 419 426 420 - let httpResponseResult = ref httpResponse 421 - match _settings.Authentication.Type with 422 - | HttpDigest -> 423 - if httpResponse.IsSome && _httpDigestInfo.IsNone && httpResponse.Value.StatusCode = HttpStatusCode.Unauthorized then 424 - // retrieve the Auth digest info and re-send the request with the correct token 425 - _httpDigestInfo <- HttpDigestAuthenticationUtility.retrieveAuthenticationInfo(httpResponse.Value) 426 - httpResponseResult := this.SendRequestDirect(httpRequest) 427 + let httpResponseResult = ref httpResponse 428 + match _settings.Authentication.Type with 429 + | HttpDigest -> 430 + if httpResponse.IsSome && _httpDigestInfo.IsNone && httpResponse.Value.StatusCode = HttpStatusCode.Unauthorized then 431 + // retrieve the Auth digest info and re-send the request with the correct token 432 + _httpDigestInfo <- HttpDigestAuthenticationUtility.retrieveAuthenticationInfo(httpResponse.Value) 433 + httpResponseResult := this.SendRequestDirect(httpRequest) 427 434 428 - | WebForm when httpResponse.IsSome && httpResponse.Value.StatusCode = HttpStatusCode.OK -> 429 - match this.SessionState with 430 - | Some _ -> 431 - if not(this.AuthenticationSuccessful([|httpResponse.Value|])) then 432 - // a specific logout condition was found, need to re-authenticate by following the Authentication Journey path 433 - if this.AuthenticationSuccessful(followPathNavigation()) then 434 - // finally re-do the request in an authentication context 435 - httpResponseResult := this.SendRequestDirect(httpRequest) 436 - else 437 - _logger.AuthenticationFailed() 435 + | WebForm when isStatusCodeValidForauthenticationCheck(httpResponse) -> 436 + match this.SessionState with 437 + | Some _ -> 438 + if not(this.AuthenticationSuccessful([|httpResponse.Value|])) then 439 + // a specific logout condition was found, need to re-authenticate by following the Authentication Journey path 440 + if this.AuthenticationSuccessful(followPathNavigation()) then 441 + // finally re-do the request in an authentication context 442 + httpResponseResult := this.SendRequestDirect(httpRequest) 443 + else 444 + _logger.AuthenticationFailed() 438 445 439 - | None -> _logger.SessionStateNullOnWebAuth() 440 - | _ -> 441 - // no authentication process needed 442 - () 446 + | None -> _logger.SessionStateNullOnWebAuth() 447 + | _ -> 448 + // no authentication process needed 449 + () 443 450 444 - // restore value 445 - _skipAuthenticationProcess <- savedValue 446 - !httpResponseResult 451 + // restore value 452 + _skipAuthenticationProcess <- savedValue 453 + !httpResponseResult 454 + ) 447 455 448 456 else 449 457 httpResponse skipped 35 lines