Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 2769936

Browse files
move refactor
1 parent bde4531 commit 2769936

3 files changed

Lines changed: 56 additions & 50 deletions

File tree

src/SqlStreamStore.HAL.Tests/SqlStreamStore.HAL.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
<PackageReference Include="xunit" Version="2.3.0-beta5-build3769" />
2525
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta5-build3769" />
2626
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta5-build3769" />
27-
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.1" />
27+
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
2828
</ItemGroup>
2929
</Project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
namespace SqlStreamStore.HAL
2+
{
3+
using System;
4+
using System.IO;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
using Microsoft.Owin;
8+
9+
internal class OptionalHeadRequestWrapper : IDisposable
10+
{
11+
private readonly IOwinContext _context;
12+
private readonly Stream _originalBody;
13+
14+
public OptionalHeadRequestWrapper(IOwinContext context)
15+
{
16+
_context = context;
17+
_originalBody = _context.Response.Body;
18+
if(context.Request.Method == "HEAD")
19+
{
20+
context.Response.Body = new HeadRequestStream();
21+
}
22+
}
23+
24+
public void Dispose()
25+
{
26+
_context.Response.Body = _originalBody;
27+
}
28+
29+
class HeadRequestStream : Stream
30+
{
31+
private long _length;
32+
33+
public override void Flush() => FlushAsync(CancellationToken.None).Wait();
34+
public override int Read(byte[] buffer, int offset, int count) => throw new NotImplementedException();
35+
public override long Seek(long offset, SeekOrigin origin) => throw new NotImplementedException();
36+
public override void SetLength(long value) => throw new NotImplementedException();
37+
public override void Write(byte[] buffer, int offset, int count) => throw new NotImplementedException();
38+
39+
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
40+
{
41+
_length += count;
42+
Position += count;
43+
return Task.CompletedTask;
44+
}
45+
46+
public override Task FlushAsync(CancellationToken cancellationToken) => Task.CompletedTask;
47+
48+
public override bool CanRead { get; } = false;
49+
public override bool CanSeek { get; } = false;
50+
public override bool CanWrite { get; } = true;
51+
public override long Length => _length;
52+
public override long Position { get; set; }
53+
}
54+
}
55+
}

src/SqlStreamStore.HAL/OwinContextExtensions.cs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,12 @@
11
namespace SqlStreamStore.HAL
22
{
3-
using System;
43
using System.IO;
5-
using System.Threading;
64
using System.Threading.Tasks;
75
using Microsoft.IO;
86
using Microsoft.Owin;
97
using Newtonsoft.Json;
108
using Newtonsoft.Json.Serialization;
119
using SqlStreamStore.Streams;
12-
13-
internal class OptionalHeadRequestWrapper : IDisposable
14-
{
15-
private readonly IOwinContext _context;
16-
private readonly Stream _originalBody;
17-
18-
public OptionalHeadRequestWrapper(IOwinContext context)
19-
{
20-
_context = context;
21-
_originalBody = _context.Response.Body;
22-
if(context.Request.Method == "HEAD")
23-
{
24-
context.Response.Body = new HeadRequestStream();
25-
}
26-
}
27-
28-
public void Dispose()
29-
{
30-
_context.Response.Body = _originalBody;
31-
}
32-
33-
class HeadRequestStream : Stream
34-
{
35-
private long _length;
36-
37-
public override void Flush() => FlushAsync(CancellationToken.None).Wait();
38-
public override int Read(byte[] buffer, int offset, int count) => throw new NotImplementedException();
39-
public override long Seek(long offset, SeekOrigin origin) => throw new NotImplementedException();
40-
public override void SetLength(long value) => throw new NotImplementedException();
41-
public override void Write(byte[] buffer, int offset, int count) => throw new NotImplementedException();
42-
43-
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
44-
{
45-
_length += count;
46-
Position += count;
47-
return Task.CompletedTask;
48-
}
49-
50-
public override Task FlushAsync(CancellationToken cancellationToken) => Task.CompletedTask;
51-
52-
public override bool CanRead { get; } = false;
53-
public override bool CanSeek { get; } = false;
54-
public override bool CanWrite { get; } = true;
55-
public override long Length => _length;
56-
public override long Position { get; set; }
57-
}
58-
}
5910

6011
internal static class OwinContextExtensions
6112
{

0 commit comments

Comments
 (0)