Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
T
tls-forward
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangmingming
tls-forward
Commits
a20b9855
Commit
a20b9855
authored
May 24, 2023
by
wangmingming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gzip解压缩问题
parent
af2d25ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
4 deletions
+73
-4
client.go
tls/client.go
+73
-4
No files found.
tls/client.go
View file @
a20b9855
package
tls
import
(
"bytes"
"compress/flate"
"compress/gzip"
"crypto/rand"
"encoding/binary"
"errors"
"github.com/andybalholm/brotli"
http
"github.com/bogdanfinn/fhttp"
tls_client
"github.com/bogdanfinn/tls-client"
"github.com/sirupsen/logrus"
"io"
"io
/ioutil
"
"math/big"
"net/url"
"strings"
...
...
@@ -90,9 +95,12 @@ func (c *Client) GetSessionCookies() map[string]string {
func
(
c
*
Client
)
GetText
()
string
{
defer
c
.
Response
.
Body
.
Close
()
http
.
DecompressBody
(
c
.
Response
)
rb
,
_
:=
io
.
ReadAll
(
c
.
Response
.
Body
)
return
string
(
rb
)
//http.DecompressBody(c.Response)
//rb, _ := io.ReadAll(c.Response.Body)
content
,
_
:=
ioutil
.
ReadAll
(
c
.
Response
.
Body
)
encoding
:=
c
.
Response
.
Header
.
Get
(
"Content-Encoding"
)
DecompressBody
(
&
content
,
encoding
)
return
string
(
content
)
}
func
(
c
*
Client
)
GetRespUrl
()
string
{
...
...
@@ -149,3 +157,64 @@ func NewClient(forWard ForwardItem, ios bool) (Client, error) {
}
return
Client
{
Client
:
client
,
Item
:
forWard
,
Jar
:
jar
,
TlsVersion
:
tlsVersion
.
GetClientHelloStr
()},
nil
}
// 解码Body数据
func
DecompressBody
(
content
*
[]
byte
,
encoding
string
)
{
if
encoding
!=
""
{
if
strings
.
ToLower
(
encoding
)
==
"gzip"
{
decodeGZip
(
content
)
}
else
if
strings
.
ToLower
(
encoding
)
==
"deflate"
{
decodeDeflate
(
content
)
}
else
if
strings
.
ToLower
(
encoding
)
==
"br"
{
decodeBrotli
(
content
)
}
}
}
// 解码GZip编码
func
decodeGZip
(
content
*
[]
byte
)
error
{
if
content
==
nil
{
return
nil
}
b
:=
new
(
bytes
.
Buffer
)
binary
.
Write
(
b
,
binary
.
LittleEndian
,
content
)
r
,
err
:=
gzip
.
NewReader
(
b
)
if
err
!=
nil
{
return
err
}
defer
r
.
Close
()
*
content
,
err
=
ioutil
.
ReadAll
(
r
)
if
err
!=
nil
{
return
err
}
return
nil
}
// 解码deflate编码
func
decodeDeflate
(
content
*
[]
byte
)
error
{
var
err
error
if
content
==
nil
{
return
err
}
r
:=
flate
.
NewReader
(
bytes
.
NewReader
(
*
content
))
defer
r
.
Close
()
*
content
,
err
=
ioutil
.
ReadAll
(
r
)
if
err
!=
nil
{
return
err
}
return
nil
}
// 解码br编码
func
decodeBrotli
(
content
*
[]
byte
)
error
{
var
err
error
if
content
==
nil
{
return
err
}
r
:=
brotli
.
NewReader
(
bytes
.
NewReader
(
*
content
))
*
content
,
err
=
ioutil
.
ReadAll
(
r
)
if
err
!=
nil
{
return
err
}
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment