Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
d2dd60a2
Commit
d2dd60a2
authored
7 years ago
by
Steven Allen
Browse files
Options
Download
Email Patches
Plain Diff
reset on error in proxy example.
parent
925ac425
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/http-proxy/proxy.go
+4
-0
examples/http-proxy/proxy.go
with
4 additions
and
0 deletions
+4
-0
examples/http-proxy/proxy.go
View file @
d2dd60a2
...
...
@@ -109,6 +109,7 @@ func streamHandler(stream inet.Stream) {
// Read the HTTP request from the buffer
req
,
err
:=
http
.
ReadRequest
(
buf
)
if
err
!=
nil
{
stream
.
Reset
()
log
.
Println
(
err
)
return
}
...
...
@@ -132,6 +133,7 @@ func streamHandler(stream inet.Stream) {
fmt
.
Printf
(
"Making request to %s
\n
"
,
req
.
URL
)
resp
,
err
:=
http
.
DefaultTransport
.
RoundTrip
(
outreq
)
if
err
!=
nil
{
stream
.
Reset
()
log
.
Println
(
err
)
return
}
...
...
@@ -176,6 +178,7 @@ func (p *ProxyService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// r.Write() writes the HTTP request to the stream.
err
=
r
.
Write
(
stream
)
if
err
!=
nil
{
stream
.
Reset
()
log
.
Println
(
err
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusServiceUnavailable
)
return
...
...
@@ -186,6 +189,7 @@ func (p *ProxyService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
buf
:=
bufio
.
NewReader
(
stream
)
resp
,
err
:=
http
.
ReadResponse
(
buf
,
r
)
if
err
!=
nil
{
stream
.
Reset
()
log
.
Println
(
err
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusServiceUnavailable
)
return
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help