Skip to content

Commit ae12a2e

Browse files
author
Jicheng Lu
committed
refine http headers
1 parent 3dfb921 commit ae12a2e

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/Infrastructure/BotSharp.Abstraction/Http/IHttpRequestHook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ namespace BotSharp.Abstraction.Http;
44

55
public interface IHttpRequestHook
66
{
7-
void OnAddHttpHeaders(HttpHeaders headers);
7+
void OnAddHttpHeaders(HttpHeaders headers, Uri uri);
88
}

src/Plugins/BotSharp.Plugin.HttpHandler/Functions/HandleHttpRequestFn.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ public async Task<bool> Execute(RoleDialogModel message)
5656
if (string.IsNullOrEmpty(url)) return null;
5757

5858
using var client = _httpClientFactory.CreateClient();
59-
PrepareRequestHeaders(client);
60-
59+
6160
var (uri, request) = BuildHttpRequest(url, method, content);
61+
PrepareRequestHeaders(client, uri);
62+
6263
var response = await client.SendAsync(request);
6364
if (response == null || !response.IsSuccessStatusCode)
6465
{
@@ -68,12 +69,12 @@ public async Task<bool> Execute(RoleDialogModel message)
6869
return response;
6970
}
7071

71-
private void PrepareRequestHeaders(HttpClient client)
72+
private void PrepareRequestHeaders(HttpClient client, Uri uri)
7273
{
7374
var hooks = _services.GetServices<IHttpRequestHook>();
7475
foreach (var hook in hooks)
7576
{
76-
hook.OnAddHttpHeaders(client.DefaultRequestHeaders);
77+
hook.OnAddHttpHeaders(client.DefaultRequestHeaders, uri);
7778
}
7879
}
7980

@@ -115,20 +116,20 @@ private HttpMethod GetHttpMethod(string? method)
115116

116117
switch (localMethod)
117118
{
118-
case "GET":
119-
matchMethod = HttpMethod.Get;
119+
case "POST":
120+
matchMethod = HttpMethod.Post;
120121
break;
121122
case "DELETE":
122123
matchMethod = HttpMethod.Delete;
123124
break;
124125
case "PUT":
125126
matchMethod = HttpMethod.Put;
126127
break;
127-
case "Patch":
128+
case "PATCH":
128129
matchMethod = HttpMethod.Patch;
129130
break;
130131
default:
131-
matchMethod = HttpMethod.Post;
132+
matchMethod = HttpMethod.Get;
132133
break;
133134
}
134135
return matchMethod;

src/Plugins/BotSharp.Plugin.HttpHandler/Hooks/BasicHttpRequestHook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public BasicHttpRequestHook(
2020
_context = context;
2121
}
2222

23-
public void OnAddHttpHeaders(HttpHeaders headers)
23+
public void OnAddHttpHeaders(HttpHeaders headers, Uri uri)
2424
{
2525
var settings = _services.GetRequiredService<HttpHandlerSettings>();
2626

0 commit comments

Comments
 (0)