Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Go Httpbin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Nix
Go Httpbin
Commits
a92e91da
Commit
a92e91da
authored
2 years ago
by
Will McCutchen
Browse files
Options
Downloads
Patches
Plain Diff
Drop usage of deprecated ioutil pkg
parent
e43229f2
Branches
Branches containing commit
Tags
v2.4.2
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
httpbin/handlers_test.go
+7
-7
7 additions, 7 deletions
httpbin/handlers_test.go
httpbin/helpers.go
+2
-3
2 additions, 3 deletions
httpbin/helpers.go
with
9 additions
and
10 deletions
httpbin/handlers_test.go
+
7
−
7
View file @
a92e91da
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"io
/ioutil
"
"io"
"log"
"log"
"math/rand"
"math/rand"
"mime/multipart"
"mime/multipart"
...
@@ -40,7 +40,7 @@ var app = New(
...
@@ -40,7 +40,7 @@ var app = New(
WithDefaultParams
(
testDefaultParams
),
WithDefaultParams
(
testDefaultParams
),
WithMaxBodySize
(
maxBodySize
),
WithMaxBodySize
(
maxBodySize
),
WithMaxDuration
(
maxDuration
),
WithMaxDuration
(
maxDuration
),
WithObserver
(
StdLogObserver
(
log
.
New
(
io
util
.
Discard
,
""
,
0
))),
WithObserver
(
StdLogObserver
(
log
.
New
(
io
.
Discard
,
""
,
0
))),
)
)
var
handler
=
app
.
Handler
()
var
handler
=
app
.
Handler
()
...
@@ -1489,7 +1489,7 @@ func TestGzip(t *testing.T) {
...
@@ -1489,7 +1489,7 @@ func TestGzip(t *testing.T) {
t
.
Fatalf
(
"error creating gzip reader: %s"
,
err
)
t
.
Fatalf
(
"error creating gzip reader: %s"
,
err
)
}
}
unzippedBody
,
err
:=
io
util
.
ReadAll
(
gzipReader
)
unzippedBody
,
err
:=
io
.
ReadAll
(
gzipReader
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"error reading gzipped body: %s"
,
err
)
t
.
Fatalf
(
"error reading gzipped body: %s"
,
err
)
}
}
...
@@ -1533,7 +1533,7 @@ func TestDeflate(t *testing.T) {
...
@@ -1533,7 +1533,7 @@ func TestDeflate(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
body
,
err
:=
io
util
.
ReadAll
(
reader
)
body
,
err
:=
io
.
ReadAll
(
reader
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -1805,7 +1805,7 @@ func TestDrip(t *testing.T) {
...
@@ -1805,7 +1805,7 @@ func TestDrip(t *testing.T) {
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
body
,
_
:=
io
util
.
ReadAll
(
resp
.
Body
)
body
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"error reading response body: %s"
,
err
)
t
.
Fatalf
(
"error reading response body: %s"
,
err
)
}
}
...
@@ -1829,7 +1829,7 @@ func TestDrip(t *testing.T) {
...
@@ -1829,7 +1829,7 @@ func TestDrip(t *testing.T) {
}
}
// in this case, the timeout happens while trying to read the body
// in this case, the timeout happens while trying to read the body
body
,
err
:=
io
util
.
ReadAll
(
resp
.
Body
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatal
(
"expected timeout reading body"
)
t
.
Fatal
(
"expected timeout reading body"
)
}
}
...
@@ -1892,7 +1892,7 @@ func TestDrip(t *testing.T) {
...
@@ -1892,7 +1892,7 @@ func TestDrip(t *testing.T) {
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
body
,
err
:=
io
util
.
ReadAll
(
resp
.
Body
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"error reading response body: %s"
,
err
)
t
.
Fatalf
(
"error reading response body: %s"
,
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
httpbin/helpers.go
+
2
−
3
View file @
a92e91da
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"math/rand"
"math/rand"
"net/http"
"net/http"
"net/url"
"net/url"
...
@@ -109,7 +108,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error
...
@@ -109,7 +108,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error
// Always set resp.Data to the incoming request body, in case we don't know
// Always set resp.Data to the incoming request body, in case we don't know
// how to handle the content type
// how to handle the content type
body
,
err
:=
io
util
.
ReadAll
(
r
.
Body
)
body
,
err
:=
io
.
ReadAll
(
r
.
Body
)
if
err
!=
nil
{
if
err
!=
nil
{
r
.
Body
.
Close
()
r
.
Body
.
Close
()
return
err
return
err
...
@@ -119,7 +118,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error
...
@@ -119,7 +118,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error
// After reading the body to populate resp.Data, we need to re-wrap it in
// After reading the body to populate resp.Data, we need to re-wrap it in
// an io.Reader for further processing below
// an io.Reader for further processing below
r
.
Body
.
Close
()
r
.
Body
.
Close
()
r
.
Body
=
io
util
.
NopCloser
(
bytes
.
NewBuffer
(
body
))
r
.
Body
=
io
.
NopCloser
(
bytes
.
NewBuffer
(
body
))
ct
:=
r
.
Header
.
Get
(
"Content-Type"
)
ct
:=
r
.
Header
.
Get
(
"Content-Type"
)
switch
{
switch
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment