Skip to content

Commit f1daac7

Browse files
committed
Core - Add IResponse.SetHeaderByName/GetHeaderByName
1 parent 01d775a commit f1daac7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

CefSharp.Core/Internals/CefResponseWrapper.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ namespace CefSharp
180180
}
181181
}
182182

183+
virtual String^ GetHeaderByName(String^ name)
184+
{
185+
ThrowIfDisposed();
186+
187+
return StringUtils::ToClr(_response->GetHeaderByName(StringUtils::ToNative(name)));
188+
}
189+
190+
virtual void SetHeaderByName(String^ name, String^ value, bool overwrite)
191+
{
192+
ThrowIfDisposed();
193+
ThrowIfReadOnly();
194+
195+
_response->SetHeaderByName(StringUtils::ToNative(name), StringUtils::ToNative(value), overwrite);
196+
}
197+
183198
void ThrowIfReadOnly()
184199
{
185200
if (_response->IsReadOnly())

CefSharp/IResponse.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,22 @@ public interface IResponse : IDisposable
4747
/// Status Text
4848
/// </summary>
4949
string StatusText { get; set; }
50+
51+
/// <summary>
52+
/// Returns the first header value for name or an empty string if not found.
53+
/// Will not return the Referer value if any. Use <see cref="Headers"/> instead if name might have multiple values.
54+
/// </summary>
55+
/// <param name="name">header name</param>
56+
/// <returns>Returns the first header value for name or an empty string if not found.</returns>
57+
string GetHeaderByName(string name);
58+
59+
/// <summary>
60+
/// Set the header name to value. The Referer value cannot be set using this method.
61+
/// Use <see cref="SetReferrer(string, ReferrerPolicy)"/> instead.
62+
/// </summary>
63+
/// <param name="name">header name</param>
64+
/// <param name="value">new header value</param>
65+
/// <param name="overwrite">If overwrite is true any existing values will be replaced with the new value. If overwrite is false any existing values will not be overwritten</param>
66+
void SetHeaderByName(string name, string value, bool overwrite);
5067
}
5168
}

0 commit comments

Comments
 (0)