-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from seionmoya/websocket-server
Rework HttpClient
- Loading branch information
Showing
12 changed files
with
327 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Net.Http; | ||
using Fuyu.Common.Compression; | ||
|
||
namespace Fuyu.Common.Networking | ||
{ | ||
public class EftHttpClient : HttpClient | ||
{ | ||
public readonly string Cookie; | ||
|
||
public EftHttpClient(string address, string sessionId) : base(address) | ||
{ | ||
Cookie = $"PHPSESSID={sessionId}"; | ||
} | ||
|
||
protected override byte[] OnSendBody(byte[] body) | ||
{ | ||
return Zlib.Compress(body, ZlibCompression.Level9); | ||
} | ||
|
||
protected override byte[] OnReceiveBody(byte[] body) | ||
{ | ||
if (Zlib.IsCompressed(body)) | ||
{ | ||
body = Zlib.Decompress(body); | ||
} | ||
|
||
return body; | ||
} | ||
|
||
protected override HttpRequestMessage GetNewRequest(HttpMethod method, string path) | ||
{ | ||
var request = new HttpRequestMessage() | ||
{ | ||
Method = method, | ||
RequestUri = new Uri(Address + path), | ||
}; | ||
|
||
if (!string.IsNullOrWhiteSpace(Cookie)) | ||
{ | ||
request.Headers.Add("Cookie", Cookie); | ||
} | ||
|
||
return request; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Net; | ||
|
||
namespace Fuyu.Common.Networking | ||
{ | ||
public class HttpResponse | ||
{ | ||
// TODO: | ||
// * use enum instead | ||
// -- seionmoya, 2024/09/19 | ||
public HttpStatusCode Status; | ||
|
||
// TODO: | ||
// * use System.Memory<byte> instead | ||
// -- seionmoya, 2024/09/19 | ||
public byte[] Body; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Fuyu.Common.Networking | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace Fuyu.Common.Networking | ||
{ | ||
public class RouteNotFoundException : Exception | ||
{ | ||
public RouteNotFoundException(string message) : base(message) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Fuyu.Common.Networking | ||
|
Oops, something went wrong.