Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 616f3bc

Browse files
committed
Add explicit Referer Header
1 parent 5a4702a commit 616f3bc

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/ServiceStack.Text/HttpRequestConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class HttpRequestConfig
1111
public string? Accept { get; set; }
1212
public string? UserAgent { get; set; }
1313
public string? ContentType { get; set; }
14+
public string? Referer { get; set; }
1415
public NameValue? Authorization { get; set; }
1516
public LongRange? Range { get; set; }
1617
public List<NameValue> Headers { get; set; } = new();

src/ServiceStack.Text/HttpUtils.HttpClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,10 @@ public static HttpRequestMessage WithHeader(this HttpRequestMessage httpReq, str
10581058
throw new NotSupportedException("Can't set ContentType before Content is populated");
10591059
httpReq.Content.Headers.ContentType = new MediaTypeHeaderValue(value);
10601060
}
1061+
else if (name.Equals(HttpHeaders.Referer, StringComparison.OrdinalIgnoreCase))
1062+
{
1063+
httpReq.Headers.Referrer = new Uri(value);
1064+
}
10611065
else if (name.Equals(HttpHeaders.UserAgent, StringComparison.OrdinalIgnoreCase))
10621066
{
10631067
if (value.IndexOf('/') >= 0)
@@ -1097,6 +1101,8 @@ public static HttpRequestMessage With(this HttpRequestMessage httpReq, Action<Ht
10971101
headers.Add(new(HttpHeaders.UserAgent, config.UserAgent));
10981102
if (config.ContentType != null)
10991103
headers.Add(new(HttpHeaders.ContentType, config.ContentType));
1104+
if (config.Referer != null)
1105+
httpReq.Headers.Referrer = new Uri(config.Referer);
11001106
if (config.Authorization != null)
11011107
httpReq.Headers.Authorization =
11021108
new AuthenticationHeaderValue(config.Authorization.Name, config.Authorization.Value);

src/ServiceStack.Text/HttpUtils.WebRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,9 @@ public static HttpWebRequest With(this HttpWebRequest httpReq, Action<HttpReques
11261126
if (config.ContentType != null)
11271127
httpReq.ContentType = config.ContentType;
11281128

1129+
if (config.Referer != null)
1130+
httpReq.Referer = config.Referer;
1131+
11291132
if (config.Authorization != null)
11301133
httpReq.Headers[HttpHeaders.Authorization] =
11311134
config.Authorization.Name + " " + config.Authorization.Value;

0 commit comments

Comments
 (0)