Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
gost
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
gost
Commits
af98b99a
Commit
af98b99a
authored
Jan 10, 2019
by
ginuerzh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix obfs-http server
parent
acc44b68
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
9 deletions
+24
-9
obfs.go
obfs.go
+24
-9
No files found.
obfs.go
View file @
af98b99a
...
@@ -6,7 +6,7 @@ import (
...
@@ -6,7 +6,7 @@ import (
"bufio"
"bufio"
"bytes"
"bytes"
"fmt"
"fmt"
"io
/ioutil
"
"io"
"net"
"net"
"net/http"
"net/http"
"net/http/httputil"
"net/http/httputil"
...
@@ -67,7 +67,8 @@ func (l *obfsHTTPListener) Accept() (net.Conn, error) {
...
@@ -67,7 +67,8 @@ func (l *obfsHTTPListener) Accept() (net.Conn, error) {
type
obfsHTTPConn
struct
{
type
obfsHTTPConn
struct
{
net
.
Conn
net
.
Conn
host
string
host
string
buf
[]
byte
rbuf
bytes
.
Buffer
wbuf
bytes
.
Buffer
isServer
bool
isServer
bool
handshaked
bool
handshaked
bool
handshakeMutex
sync
.
Mutex
handshakeMutex
sync
.
Mutex
...
@@ -106,11 +107,14 @@ func (c *obfsHTTPConn) serverHandshake() (err error) {
...
@@ -106,11 +107,14 @@ func (c *obfsHTTPConn) serverHandshake() (err error) {
}
}
if
r
.
ContentLength
>
0
{
if
r
.
ContentLength
>
0
{
c
.
buf
,
err
=
ioutil
.
ReadAll
(
r
.
Body
)
_
,
err
=
io
.
Copy
(
&
c
.
rbuf
,
r
.
Body
)
}
else
{
}
else
{
c
.
buf
,
err
=
br
.
Peek
(
br
.
Buffered
())
var
b
[]
byte
b
,
err
=
br
.
Peek
(
br
.
Buffered
())
if
len
(
b
)
>
0
{
_
,
err
=
c
.
rbuf
.
Write
(
b
)
}
}
}
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Logf
(
"[ohttp] %s -> %s : %v"
,
c
.
Conn
.
RemoteAddr
(),
c
.
Conn
.
LocalAddr
(),
err
)
log
.
Logf
(
"[ohttp] %s -> %s : %v"
,
c
.
Conn
.
RemoteAddr
(),
c
.
Conn
.
LocalAddr
(),
err
)
return
return
...
@@ -138,6 +142,12 @@ func (c *obfsHTTPConn) serverHandshake() (err error) {
...
@@ -138,6 +142,12 @@ func (c *obfsHTTPConn) serverHandshake() (err error) {
if
Debug
{
if
Debug
{
log
.
Logf
(
"[ohttp] %s <- %s
\n
%s"
,
c
.
Conn
.
RemoteAddr
(),
c
.
Conn
.
LocalAddr
(),
b
.
String
())
log
.
Logf
(
"[ohttp] %s <- %s
\n
%s"
,
c
.
Conn
.
RemoteAddr
(),
c
.
Conn
.
LocalAddr
(),
b
.
String
())
}
}
if
c
.
rbuf
.
Len
()
>
0
{
c
.
wbuf
=
b
// cache the response header if there are extra data in the request body.
return
}
_
,
err
=
b
.
WriteTo
(
c
.
Conn
)
_
,
err
=
b
.
WriteTo
(
c
.
Conn
)
return
return
}
}
...
@@ -182,10 +192,8 @@ func (c *obfsHTTPConn) Read(b []byte) (n int, err error) {
...
@@ -182,10 +192,8 @@ func (c *obfsHTTPConn) Read(b []byte) (n int, err error) {
if
err
=
c
.
Handshake
();
err
!=
nil
{
if
err
=
c
.
Handshake
();
err
!=
nil
{
return
return
}
}
if
len
(
c
.
buf
)
>
0
{
if
c
.
rbuf
.
Len
()
>
0
{
n
=
copy
(
b
,
c
.
buf
)
return
c
.
rbuf
.
Read
(
b
)
c
.
buf
=
c
.
buf
[
n
:
]
return
}
}
return
c
.
Conn
.
Read
(
b
)
return
c
.
Conn
.
Read
(
b
)
}
}
...
@@ -194,6 +202,13 @@ func (c *obfsHTTPConn) Write(b []byte) (n int, err error) {
...
@@ -194,6 +202,13 @@ func (c *obfsHTTPConn) Write(b []byte) (n int, err error) {
if
err
=
c
.
Handshake
();
err
!=
nil
{
if
err
=
c
.
Handshake
();
err
!=
nil
{
return
return
}
}
if
c
.
wbuf
.
Len
()
>
0
{
c
.
wbuf
.
Write
(
b
)
// append the data to the cached header
_
,
err
=
c
.
wbuf
.
WriteTo
(
c
.
Conn
)
n
=
len
(
b
)
// exclude the header length
return
}
return
c
.
Conn
.
Write
(
b
)
return
c
.
Conn
.
Write
(
b
)
}
}
...
...
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