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

Commit 9b679e5

Browse files
unrelated but fixing this broken window
1 parent 3873a23 commit 9b679e5

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/SqlStreamStore.HAL/SqlStreamStoreHalMiddleware.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,30 @@ private class OptionalHeadRequestWrapper : IDisposable
104104
{
105105
private readonly HttpContext _context;
106106
private readonly Stream _originalBody;
107+
private readonly bool _isHeadRequest;
107108

108109
public OptionalHeadRequestWrapper(HttpContext context)
109110
{
110111
_context = context;
111-
_originalBody = _context.Response.Body;
112-
if(_context.Request.Method == "HEAD")
112+
if(_context.Request.Method != "HEAD")
113113
{
114-
_context.Request.Method = "GET";
115-
_context.Response.Body = new HeadRequestStream();
114+
return;
116115
}
116+
117+
_isHeadRequest = true;
118+
_originalBody = _context.Response.Body;
119+
_context.Request.Method = "GET";
120+
_context.Response.Body = new HeadRequestStream();
117121
}
118122

119123
public void Dispose()
120124
{
121-
_context.Response.Body = _originalBody;
122-
if(_context.Request.Method == "GET")
125+
if(!_isHeadRequest)
123126
{
124-
_context.Request.Method = "HEAD";
127+
return;
125128
}
129+
_context.Response.Body = _originalBody;
130+
_context.Request.Method = "HEAD";
126131
}
127132

128133
private class HeadRequestStream : Stream

0 commit comments

Comments
 (0)