public async Task <IDictionary <string, string> > Response(IDictionary <string, string> request) { this.requestVerification.Verify(request); System.Net.ServicePointManager.FindServicePoint( new Address.Of(request).Value() ).ConnectionLeaseTimeout = (int)this.timeout.TotalMilliseconds; // see http://byterot.blogspot.com/2016/07/singleton-httpclient-dns.html using (var aspnetResponse = AspNetResponse(AspNetRequest(request))) using (var responseContent = aspnetResponse.Content) using (var responseStream = await responseContent.ReadAsStreamAsync()) { var body = new BytesOf( new InputOf(responseStream) ).AsBytes(); // read stream to end, before it gets disposed var response = new Responses.Response.Of( new Status((int)aspnetResponse.StatusCode), new Reason(aspnetResponse.ReasonPhrase), new Headers(ResponseHeaders(aspnetResponse)), new Conditional( () => body.Length > 0, new Body(body) ) ); return(response); } }
public void ParallelAccessWorks() { var content = new BytesOf("Works").AsBytes(); var accesses = 0; var cell = new FkCell( (update) => { }, () => { accesses++; Assert.Equal(1, accesses); accesses--; return(content); } ); var valve = new LocalSyncPipe(); Parallel.For(0, Environment.ProcessorCount << 4, (i) => { Assert.Equal( "Works", new TextOf( new SyncCell(cell, valve).Content() ).AsString() ); }); }
public void HasBytes() { var expected = new BytesOf("important data").AsBytes(); Assert.Equal( expected, new BytesOf( new Body.Of( new BytesResponse.Of(expected) ) ).AsBytes() ); }
public void RemovesXml() { var mem = new RamMnemonic(); var cache = new CachedMnemonic(mem); var data = new BytesOf(new InputOf("splashy")).AsBytes(); cache.Contents().UpdateXml("splashy.xml", new XDocument(new XElement("splashy"))); cache.Contents().UpdateXml("splashy.xml", new XDocument()); Assert.Equal( "<root />", cache.Contents().Xml("splashy.xml", () => new XDocument(new XElement("root"))).ToString() ); }
public void Update(IInput content) { var stream = content.Stream(); stream.Seek(0, SeekOrigin.Begin); var data = new BytesOf( new InputOf(stream) ).AsBytes(); this.mem .Value() .Contents() .UpdateBytes( this.name.AsString(), data ); }
public void CachesBytesOnRead() { var mem = new RamMnemonic(); var cache = new CachedMnemonic(mem); var data = new BytesOf(new InputOf("splashy")).AsBytes(); cache.Contents().Bytes("cashy", () => data); //read 1 mem.Contents().UpdateBytes("cashy", new byte[0]); Assert.Equal( "splashy", new TextOf( new InputOf( cache.Contents() .Bytes("cashy", () => throw new ApplicationException($"Assumed to have memory")) ) ).AsString() ); }