Skip to content

Commit

Permalink
dat全件取得時のhttps/5ch -> 2chリンク置換 #12
Browse files Browse the repository at this point in the history
  • Loading branch information
onihusube committed Jul 11, 2023
1 parent f25565e commit 8cf9825
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions 2chAPIProxy/DatProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public DatProxy(String Akey, String Hkey, String ua1, String sidUA, String ua2,
GetDat(ref oSession, is2ch);
return;
*/
if (ViewModel.Setting.UseTLSWrite) oSession.fullUrl = oSession.fullUrl.Replace("http://", "https://");
// レスポンス返し直前に介入する
oSession.bBufferResponse = true;
Expand All @@ -167,6 +168,9 @@ public DatProxy(String Akey, String Hkey, String ua1, String sidUA, String ua2,
intervene_in_dat_response(ref ooSession, is2ch);
};
FiddlerApplication.BeforeResponse += BRHandler;
System.Diagnostics.Debug.WriteLine("dat URI:" + oSession.fullUrl);
return;
}
else if (GetHTML && (CheckKakouri.IsMatch(oSession.fullUrl) || CheckKakouri2.IsMatch(oSession.fullUrl)))
Expand Down Expand Up @@ -1478,6 +1482,12 @@ private void intervene_in_dat_response(ref Session oSession, bool is2ch)
{
try
{
if (is2ch && string.IsNullOrEmpty(oSession.oResponse.headers["Set-Cookie"]) == false)
{
// クッキーのホストを変換
oSession.oResponse.headers["Set-Cookie"] = oSession.oResponse.headers["Set-Cookie"].Replace("5ch.net", "2ch.net");
}

switch (oSession.responseCode)
{
case 206:
Expand All @@ -1491,6 +1501,34 @@ private void intervene_in_dat_response(ref Session oSession, bool is2ch)
return;
case 200:
// 全件取得
if (ViewModel.Setting.Replace5chURI || ViewModel.Setting.ReplaceHttpsLink || CRReplace)
{
// 全件取得時のみgzip圧縮されている
oSession.utilDecodeResponse();

var resdat = Encoding.GetEncoding("Shift_JIS").GetString(oSession.responseBodyBytes);

if (ViewModel.Setting.Replace5chURI || ViewModel.Setting.ReplaceHttpsLink)
{
resdat = HtmlConverter.ResContentReplace(resdat);
}

if (CRReplace)
{
// スレタイの©マークを置換
var re = new Regex(@"^.+?<>.*?<>.+?<>.+?<>(.+?&#169;.+?)\t");

if (re.IsMatch(resdat))
{
// 最初の一個だけを置換
resdat = re.Replace(@"&#169;", "&copy;", 1);
}
}

oSession.ResponseBody = Encoding.GetEncoding("Shift_JIS").GetBytes(resdat);
}

if (gZipRes) oSession.utilGZIPResponse();
return;
case 404:
case 302:
Expand Down
2 changes: 1 addition & 1 deletion 2chAPIProxy/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:_2chAPIProxy" mc:Ignorable="d" x:Class="_2chAPIProxy.MainWindow"
Title="2chAPIProxy Ver:2023.07.11 nonAPI" Height="480" Width="640"
Title="2chAPIProxy Ver:2023.07.12 nonAPI test" Height="480" Width="640"
Icon="icon3.ico" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" Background="White" d:DataContext="{d:DesignInstance {x:Type local:ViewModel}}">
<Window.InputBindings>
<KeyBinding Gesture="Ctrl+S" Command="{Binding SaveSetting}"/>
Expand Down

0 comments on commit 8cf9825

Please sign in to comment.