public HttpTrafficHandler(IHttpRequestBuilder httpRequestBuilder, IHttpRequestExecutor httpRequestExecutor, IHttpResponseBuilder httpResponseBuilder) { _httpRequestBuilder = httpRequestBuilder; _httpRequestExecutor = httpRequestExecutor; _httpResponseBuilder = httpResponseBuilder; }
public static IHttpRequestBuilder SetDefaultADORequestValues(this IHttpRequestBuilder builder, string accessToken) { return(builder .QueryParameter("api-version", "5.0") .Header("Authorization", "Bearer " + accessToken) .Header("Accept-Encoding", "gzip")); }
public void setup() { _subject = new HttpRequestBuilder(); target = new Uri("http://www.example.com/my/path"); _subject.Get(target).SetHeader("User-Agent", "Phil's face"); }
public void setup() { _subject = new HttpRequestBuilder(); target = new Uri("http://www.example.com/my/path"); _subject.Get(target).BasicAuthentication("Aladdin", "open sesame"); }
public void setup() { _subject = new HttpRequestBuilder(); target = new Uri("http://www.example.com/my/path"); _subject.Get(target).SetHeader("User-Agent", "Phil's face"); }
public void setup() { _subject = new HttpRequestBuilder(); target = new Uri("http://www.example.com/my/path"); _subject.Get(target).BasicAuthentication("Aladdin","open sesame"); }
/// <summary> /// Sets an authenticated <see cref="Microsoft.AspNetCore.Http.HttpContext.User"/> to the built request with the provided identifier (Id), username and optional roles. /// </summary> /// <param name="httpRequestBuilder">Instance of <see cref="IHttpRequestBuilder"/> type.</param> /// <param name="identifier">Value of the identifier (Id) claim - <see cref="System.Security.Claims.ClaimTypes.NameIdentifier"/>.</param> /// <param name="username">Value of the username claim. Default claim type is <see cref="System.Security.Claims.ClaimTypes.Name"/>.</param> /// <param name="roles">Collection of role names to add.</param> /// <returns>The same component builder.</returns> public static IAndHttpRequestBuilder WithUser( this IHttpRequestBuilder httpRequestBuilder, string identifier, string username, params string[] roles) => httpRequestBuilder .WithUser(identifier, username, roles.AsEnumerable());
/// <summary> /// Sets default authenticated <see cref="Microsoft.AspNetCore.Http.HttpContext.User"/> to the built request with "TestId" identifier and "TestUser" username. /// </summary> /// <param name="httpRequestBuilder">Instance of <see cref="IHttpRequestBuilder"/> type.</param> /// <returns>The same <see cref="IAndHttpRequestBuilder"/>.</returns> public static IAndHttpRequestBuilder WithUser(this IHttpRequestBuilder httpRequestBuilder) { var actualHttpRequestBuilder = (HttpRequestBuilder)httpRequestBuilder; actualHttpRequestBuilder.HttpContext.User = ClaimsPrincipalBuilder.DefaultAuthenticated; return(actualHttpRequestBuilder); }
public void CrossLoad(IHttpRequest loadRequest, IHttpRequestBuilder storeRequest) { using (var getTx = Request(loadRequest)) // get source { var storeRq = storeRequest.Data(getTx.RawBodyStream, getTx.BodyReader.ExpectedLength).Build(); Request(storeRq).Dispose(); // write out to dest } }
public void setup() { _subject = new HttpRequestBuilder(); target = new Uri("http://www.example.com/my/path"); _data = Lorem.Ipsum(); _subject.Post(target).StringData(_data).SetHeader("User-Agent", "Phil's face"); }
/// <summary> /// Sets an authenticated <see cref="Microsoft.AspNetCore.Http.HttpContext.User"/> to the built request with "TestId" identifier (Id) and the provided username and roles. /// </summary> /// <param name="httpRequestBuilder">Instance of <see cref="IHttpRequestBuilder"/> type.</param> /// <param name="username">Value of the username claim. Default claim type is <see cref="System.Security.Claims.ClaimTypes.Name"/>.</param> /// <param name="roles">Collection of role names to add.</param> /// <returns>The same component builder.</returns> public static IAndHttpRequestBuilder WithUser( this IHttpRequestBuilder httpRequestBuilder, string username, IEnumerable <string> roles) => httpRequestBuilder .WithUser(user => user .WithUsername(username) .InRoles(roles));
public void CrossLoad(IHttpRequest loadRequest, IHttpRequestBuilder storeRequest) { using (var getTx = Request(loadRequest)) // get source { var storeRq = storeRequest.Data(getTx.RawBodyStream, getTx.BodyReader.ExpectedLength).Build(); Request(storeRq).Dispose(); // write out to dest } }
public WebApiClient(IHttpRequestBuilder httpRequestBuilder) { if (_client == null) { _client = new System.Net.Http.HttpClient(); } _httpRequestBuilder = httpRequestBuilder; }
public void setup() { _subject = new HttpRequestBuilder(); target = new Uri("http://www.example.com/my/path"); _localTarget = "/my/path"; _verb = "PURGE"; _subject.Verb(_verb, target).SetHeader("User-Agent", "Phil's face"); }
public void setup() { _subject = new HttpRequestBuilder(); target = new Uri("http://www.example.com/my/path"); _localTarget = "/my/path"; _verb = "PURGE"; _subject.Verb(_verb, target).SetHeader("User-Agent", "Phil's face"); }
public ResourceRetriever( IHttpRequestBuilder httpRequestBuilder, IHttpClient httpClient, IXmlSerializerWrapper serializerWrapper) { _httpRequestBuilder = httpRequestBuilder; _httpClient = httpClient; _serializerWrapper = serializerWrapper; }
public void setup() { _subject = new HttpRequestBuilder(); target = new Uri("http://www.example.com/my/path"); _data = Lorem.Ipsum(); _dataStream = new MemoryStream(Encoding.UTF8.GetBytes(_data)); _subject.Put(target).Data(_dataStream, _data.Length).SetHeader("User-Agent", "Phil's face"); }
public void setup() { _subject = new HttpRequestBuilder(); target = new Uri("http://www.example.com/my/path"); _data = Lorem.Ipsum(); _dataStream = new MemoryStream(Encoding.UTF8.GetBytes(_data)); _subject.Put(target).Data(_dataStream, _data.Length).SetHeader("User-Agent", "Phil's face"); }
public void Setup() { _subject = new HttpRequestBuilder(); _target = new Uri("http://www.example.com/my/path"); _localTarget = "/my/path"; _data = Lorem.Ipsum(); _request = _subject.Post(_target).SetHeader("User-Agent", "Phil's face").Build(_data); }
public void Setup() { _subject = new HttpRequestBuilder(); _target = new Uri("http://www.example.com/my/path"); _localTarget = "/my/path"; _data = Lorem.Ipsum(); _request = _subject.Post(_target).SetHeader("User-Agent", "Phil's face").Build(_data); }
/// <summary> /// Request data from one resource and provide to another. /// This is done in a memory-efficient manner. /// </summary> /// <param name="loadRequest">Request that will provide body data (should be a GET or POST)</param> /// <param name="storeRequest">Request that will accept body data (should be a PUT or POST)</param> /// <exception cref="ShiftIt.Http.HttpTransferException">Response to the request was not a succesful HTTP status.</exception> /// <exception cref="System.Net.Sockets.SocketException">Low level transport exception occured.</exception> /// <exception cref="ShiftIt.Http.TimeoutException">A timeout occured during transfer.</exception> public void CrossLoad(IHttpRequest loadRequest, IHttpRequestBuilder storeRequest) { using (var getTx = RequestOrThrow(loadRequest)) // get source { var storeRq = storeRequest.Build(getTx.RawBodyStream, getTx.BodyReader.ExpectedLength); using (RequestOrThrow(storeRq)) // dispose of the response stream { } } }
/// <summary> /// Request data from one resource and provide to another. /// This is done in a memory-efficient manner. /// </summary> /// <param name="loadRequest">Request that will provide body data (should be a GET or POST)</param> /// <param name="storeRequest">Request that will accept body data (should be a PUT or POST)</param> /// <param name="sendProgress">Optional: action that is updated with bytes transferred. No guarantees as to when.</param> /// <exception cref="ShiftIt.Http.HttpTransferException">Response to the request was not a succesful HTTP status.</exception> /// <exception cref="System.Net.Sockets.SocketException">Low level transport exception occured.</exception> /// <exception cref="ShiftIt.Http.TimeoutException">A timeout occured during transfer.</exception> public void CrossLoad(IHttpRequest loadRequest, IHttpRequestBuilder storeRequest, Action <long> sendProgress = null) { using (var getTx = RequestOrThrow(loadRequest)) // get source { var storeRq = storeRequest.Build(getTx.RawBodyStream, getTx.BodyReader.ExpectedLength); using (RequestOrThrow(storeRq)) // dispose of the response stream { } } }
public static async Task <TResponse> DispatchAsync <TResponse>(this IHttpRequestBuilder httpRequestBuilder) { var httpRequest = httpRequestBuilder.Build(); var response = await Client.SendAsync(httpRequest); var responseContent = await response.Content.ReadAsStringAsync(); //TODO: consider a strategy for non-success responses //if (!task.Result.IsSuccessStatusCode) throw new Exception(result); return(JsonConvert.DeserializeObject <TResponse>(responseContent)); }
public byte[] CrossLoad(IHttpRequest loadRequest, IHttpRequestBuilder storeRequest, string hashAlgorithmName) { var hash = HashAlgorithm.Create(hashAlgorithmName); using (var getTx = Request(loadRequest)) { var hashStream = new HashingReadStream(getTx.RawBodyStream, hash); var storeRq = storeRequest.Data(hashStream, getTx.BodyReader.ExpectedLength).Build(); Request(storeRq).Dispose(); return hashStream.GetHashValue(); } }
public static IHttpRequestBuilder RequestBody(this IHttpRequestBuilder requestBuilder, string requestBody, string contentType = null) { if (contentType != null) { requestBuilder.ContentType = contentType; } requestBuilder.RequestBody = requestBody; return(requestBuilder); }
public LinkService ( IEndPoint apiEndpoint, IHttpRequestBuilder httpRequestBuilder, IHttpReadClient httpClient ) { _apiEndpoint = apiEndpoint ?? throw new ArgumentNullException(nameof(apiEndpoint)); _httpRequestBuilder = httpRequestBuilder ?? throw new ArgumentNullException(nameof(httpRequestBuilder)); _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); }
public byte[] CrossLoad(IHttpRequest loadRequest, IHttpRequestBuilder storeRequest, string hashAlgorithmName) { var hash = HashAlgorithm.Create(hashAlgorithmName); using (var getTx = Request(loadRequest)) { var hashStream = new HashingReadStream(getTx.RawBodyStream, hash); var storeRq = storeRequest.Data(hashStream, getTx.BodyReader.ExpectedLength).Build(); Request(storeRq).Dispose(); return(hashStream.GetHashValue()); } }
/// <summary> /// Sets custom authenticated <see cref="Microsoft.AspNetCore.Http.HttpContext.User"/> to the built request using the provided user builder. /// </summary> /// <param name="httpRequestBuilder">Instance of <see cref="IHttpRequestBuilder"/> type.</param> /// <param name="userBuilder">Action setting the <see cref="Microsoft.AspNetCore.Http.HttpContext.User"/> by using <see cref="IClaimsPrincipalBuilder"/>.</param> /// <returns>The same <see cref="IAndHttpRequestBuilder"/>.</returns> public static IAndHttpRequestBuilder WithUser( this IHttpRequestBuilder httpRequestBuilder, Action <IClaimsPrincipalBuilder> userBuilder) { var actualHttpRequestBuilder = (HttpRequestBuilder)httpRequestBuilder; var newUserBuilder = new ClaimsPrincipalBuilder(); userBuilder(newUserBuilder); actualHttpRequestBuilder.HttpContext.User = newUserBuilder.GetClaimsPrincipal(); return(actualHttpRequestBuilder); }
// -------------------------------------------------- // // HttpRequestBuilder setup // // -------------------------------------------------- public ServiceTestBuilder <TItem> HttpRequestBuilder_BuildAsync ( HttpMethod method, string url, HttpRequestMessage request ) { var creator = new Mock <IHttpRequestBuilder>(MockBehavior.Strict); creator.Setup(b => b.BuildAsync(method, url)).ReturnsAsync(request); HttpRequestBuilder = creator.Object; return(this); }
public RestClient( HttpClient client, IHttpRequestBuilder httpRequestBuilder, ISerializer serializer, IExecutor <HttpRequestMessage, HttpResponseMessage> executor, Action <HeadersBuilder> defaultHeaders) { _client = client; _httpRequestBuilder = httpRequestBuilder; _serializer = serializer; _executor = executor; _defaultHeaders = defaultHeaders; }
/// <summary> /// Request data from one resource and provide to another, calculating a /// hash of the cross-loaded data. This is done in a memory-efficient manner. /// If either source or destination return a non-success result (including redirects) /// an exception will be thrown /// </summary> /// <param name="loadRequest">Request that will provide body data (should be a GET or POST)</param> /// <param name="storeRequest">Request that will accept body data (should be a PUT or POST)</param> /// <param name="hashAlgorithmName">Name of hash algorithm to use (should be a name supported by <see cref="System.Security.Cryptography.HashAlgorithm"/>)</param> /// <exception cref="ShiftIt.Http.HttpTransferException">Response to the request was not a succesful HTTP status.</exception> /// <exception cref="System.Net.Sockets.SocketException">Low level transport exception occured.</exception> /// <exception cref="ShiftIt.Http.TimeoutException">A timeout occured during transfer.</exception> public byte[] CrossLoad(IHttpRequest loadRequest, IHttpRequestBuilder storeRequest, string hashAlgorithmName) { var hash = HashAlgorithm.Create(hashAlgorithmName); using (var getTx = RequestOrThrow(loadRequest)) { var hashStream = new HashingReadStream(getTx.RawBodyStream, hash); var storeRq = storeRequest.Build(hashStream, getTx.BodyReader.ExpectedLength); using (RequestOrThrow(storeRq)) // dispose of the response stream { } return(hashStream.GetHashValue()); } }
public static async Task <TResponse> DispatchAsync <TResponse>(this IHttpRequestBuilder httpRequestBuilder, IExceptionParser exceptionParser = null) { Enforce.That.ExceptionParserHasBeenInitialized(ref exceptionParser); var httpRequest = httpRequestBuilder.Build(); var response = await _client.SendAsync(httpRequest); var responseContent = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { exceptionParser.ParseException(responseContent); } return(JsonConvert.DeserializeObject <TResponse>(responseContent)); }
public void SetUp() { CreateSearchRequest(); _headersBuilt = new Dictionary <string, string>(); _mockedUriBuilder = new Mock <IUriBuilder>(); _mockedClock = new Mock <IClock>(); _mockedSignatureBuider = new Mock <ISignatureBuilder>(); _mockedAllHeadersBuilder = new Mock <IAllHttpHeadersBuilder>(); _builder = new HttpRequestBuilder( _mockedUriBuilder.Object, _mockedClock.Object, _mockedSignatureBuider.Object, _mockedAllHeadersBuilder.Object); }
public void SetUp() { CreateSearchRequest(); _headersBuilt = new Dictionary<string, string>(); _mockedUriBuilder = new Mock<IUriBuilder>(); _mockedClock = new Mock<IClock>(); _mockedSignatureBuider = new Mock<ISignatureBuilder>(); _mockedAllHeadersBuilder = new Mock<IAllHttpHeadersBuilder>(); _builder = new HttpRequestBuilder( _mockedUriBuilder.Object, _mockedClock.Object, _mockedSignatureBuider.Object, _mockedAllHeadersBuilder.Object); }
public void Setup() { _fakeFactory = Substitute.For <IHttpRequestFactory>(); _fakeBuilder = Substitute.For <IHttpRequestBuilder>(); _fakeBuilder.SendAsync().Returns(new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest }); _fakeBuilder.AddAuthentication(Arg.Any <string>(), Arg.Any <string>()).Returns(_fakeBuilder); _userFake = Substitute.For <IUser>(); _userFake.Username = "******"; _userFake.Password = "******"; _userFake.GivenName = "TestMansen"; _userFake.LastName = "Swagattack"; _userFake.Email = "*****@*****.**"; }
public async Task <Stream> SendRequest(IHttpRequestBuilder requestBuilder, CancellationToken ct = default) { var request = requestBuilder.Build(); var httpResponse = await _httpClient.SendAsync(request, ct); if (_unauthorizedAccessResponseCodes?.Any(code => code == httpResponse.StatusCode) == true) { throw new UnauthorizedAccessException("Unauthorized request"); } var responseStream = await httpResponse.Content .ReadAsStreamAsync() .ConfigureAwait(false); return(responseStream); }
internal Session( Func <HttpClient> httpClientFactory, IHttpRequestBuilder httpRequestBuilder, ICacheProvider cache, IModelRegistry modelRegistry, JsonSerializerSettings jsonSettings, BundledHttpResponseListener httpResponseListener) { HttpClient = httpClientFactory(); HttpRequestBuilder = httpRequestBuilder; Cache = cache; ModelRegistry = modelRegistry; JsonSettings = jsonSettings; HttpResponseListener = httpResponseListener; JsonDiff = new JsonDiff(); JsonComparer = new LooseJsonEqualityComparer(); }
/// <summary> /// Adds anti-forgery token to the <see cref="Microsoft.AspNetCore.Http.HttpRequest"/>. /// </summary> /// <param name="httpRequestBuilder">Instance of <see cref="IHttpRequestBuilder"/> type.</param> /// <returns>The same <see cref="IHttpRequestBuilder"/>.</returns> public static IAndHttpRequestBuilder WithAntiForgeryToken(this IHttpRequestBuilder httpRequestBuilder) { var actualHttpRequestBuilder = (HttpRequestBuilder)httpRequestBuilder; var httpContext = actualHttpRequestBuilder.HttpContext; var antiForgery = httpContext.RequestServices.GetRequiredService <IAntiforgery>(); var antiForgeryOptions = httpContext.RequestServices.GetRequiredService <IOptions <AntiforgeryOptions> >().Value; var tokens = antiForgery.GetTokens(httpContext); if (antiForgeryOptions.Cookie.Name != null) { actualHttpRequestBuilder.WithCookie(antiForgeryOptions.Cookie.Name, tokens.CookieToken); } if (antiForgeryOptions.HeaderName != null) { actualHttpRequestBuilder.WithHeader(antiForgeryOptions.HeaderName, tokens.RequestToken); } else { actualHttpRequestBuilder.WithFormField(antiForgeryOptions.FormFieldName, tokens.RequestToken); } var antiforgeryFeature = WebFramework.Internals.IAntiforgeryFeature; var generatedAntiforgeryFeature = httpContext.Features[antiforgeryFeature].Exposed(); var newAntiforgeryFeature = Activator .CreateInstance(WebFramework.Internals.AntiforgeryFeature) .Exposed(); newAntiforgeryFeature.HaveDeserializedCookieToken = false; newAntiforgeryFeature.HaveDeserializedRequestToken = false; newAntiforgeryFeature.CookieToken = generatedAntiforgeryFeature.NewCookieToken; newAntiforgeryFeature.RequestToken = generatedAntiforgeryFeature.NewRequestToken; httpContext.Features[antiforgeryFeature] = newAntiforgeryFeature.Object; return(actualHttpRequestBuilder); }
private static Client.Session.Session CreateSession( HttpMessageHandler mockHandler = null, IHttpRequestBuilder requestBuilder = null, ICacheProvider cacheProvider = null, IModelRegistry modelRegistry = null, JsonSerializerSettings jsonSettings = null) { if (mockHandler == null) { mockHandler = new HttpClientHandler(); } return(new Client.Session.Session( () => new HttpClient(mockHandler), requestBuilder ?? Mock.Of <IHttpRequestBuilder>(), cacheProvider ?? Mock.Of <ICacheProvider>(), modelRegistry ?? Mock.Of <IModelRegistry>(), jsonSettings ?? new JsonSerializerSettings(), Mock.Of <BundledHttpResponseListener>())); }
public void SetHttpRequestBuilder(IHttpRequestBuilder builder) { Builder = builder; }
public IHttpRequest ToRequest(IHttpRequestBuilder httpRequestBuilder) { return httpRequestBuilder.BuildRequest(this); }
/// <summary> /// Request data from one resource and provide to another, calculating a /// hash of the cross-loaded data. This is done in a memory-efficient manner. /// If either source or destination return a non-success result (including redirects) /// an exception will be thrown /// </summary> /// <param name="loadRequest">Request that will provide body data (should be a GET or POST)</param> /// <param name="storeRequest">Request that will accept body data (should be a PUT or POST)</param> /// <param name="hashAlgorithmName">Name of hash algorithm to use (should be a name supported by <see cref="System.Security.Cryptography.HashAlgorithm"/>)</param> /// <exception cref="ShiftIt.Http.HttpTransferException">Response to the request was not a succesful HTTP status.</exception> /// <exception cref="System.Net.Sockets.SocketException">Low level transport exception occured.</exception> /// <exception cref="ShiftIt.Http.TimeoutException">A timeout occured during transfer.</exception> public byte[] CrossLoad(IHttpRequest loadRequest, IHttpRequestBuilder storeRequest, string hashAlgorithmName) { var hash = HashAlgorithm.Create(hashAlgorithmName); using (var getTx = RequestOrThrow(loadRequest)) { var hashStream = new HashingReadStream(getTx.RawBodyStream, hash); var storeRq = storeRequest.Build(hashStream, getTx.BodyReader.ExpectedLength); using (RequestOrThrow(storeRq)) // dispose of the response stream { } return hashStream.GetHashValue(); } }
public void some_requests() { _secured = new HttpRequestBuilder().Get(new Uri("https://secure.example.com")); _unsecured = new HttpRequestBuilder().Get(new Uri("http://www.example.com")); }
public void setup() { _subject = new HttpRequestBuilder(); target = new Uri("http://www.example.com/my/path"); _data = Lorem.Ipsum(); _subject.Post(target).StringData(_data).SetHeader("User-Agent", "Phil's face"); }