Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,49 @@ public byte[] BinaryRead(int count)
return buffer;
}

public void SaveAs(string filename, bool includeHeaders)
{
using var f = new FileStream(filename, FileMode.Create);

if (includeHeaders)
{
using var w = new StreamWriter(f, leaveOpen: true);

w.Write(HttpMethod);
w.Write(" ");
w.Write(Path);

// Includes the leading '?' if non-empty
w.Write(_request.QueryString);

w.Write(" ");
w.WriteLine(_request.Protocol);

foreach (var header in _request.Headers)
{
w.Write(header.Key);
w.Write(": ");
w.WriteLine(header.Value);
}

w.WriteLine();
}

WriteTo(InputStream, f);
}

/// <summary>
/// Copies the entire stream, but ensures the position is reset to what it was when starting
/// </summary>
private static void WriteTo(Stream source, Stream destination)
{
var currentPosition = source.Position;

source.Position = 0;
source.CopyTo(destination);
source.Position = currentPosition;
}

public void Abort() => _request.HttpContext.Abort();

[return: NotNullIfNotNull("request")]
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.AspNetCore.SystemWebAdapters/Ref.Standard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ internal HttpRequest() { }
public string[] UserLanguages { get { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");} }
public void Abort() { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");}
public byte[] BinaryRead(int count) { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");}
public void SaveAs(string filename, bool includeHeaders) { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");}
}
public abstract partial class HttpRequestBase
{
Expand Down