good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
Erigon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
a
Erigon
Commits
f258a21a
Commit
f258a21a
authored
7 years ago
by
Vitaly V
Committed by
Felix Lange
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
rpc: use method constants instead of literal strings (#15652)
parent
fd777bb2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rpc/http.go
+4
-4
4 additions, 4 deletions
rpc/http.go
rpc/http_test.go
+5
-5
5 additions, 5 deletions
rpc/http_test.go
with
9 additions
and
9 deletions
rpc/http.go
+
4
−
4
View file @
f258a21a
...
...
@@ -67,7 +67,7 @@ func (hc *httpConn) Close() error {
// DialHTTP creates a new RPC clients that connection to an RPC server over HTTP.
func
DialHTTP
(
endpoint
string
)
(
*
Client
,
error
)
{
req
,
err
:=
http
.
NewRequest
(
"POST"
,
endpoint
,
nil
)
req
,
err
:=
http
.
NewRequest
(
http
.
MethodPost
,
endpoint
,
nil
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -149,7 +149,7 @@ func NewHTTPServer(cors []string, srv *Server) *http.Server {
// ServeHTTP serves JSON-RPC requests over HTTP.
func
(
srv
*
Server
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
// Permit dumb empty requests for remote health-checks (AWS)
if
r
.
Method
==
"GET"
&&
r
.
ContentLength
==
0
&&
r
.
URL
.
RawQuery
==
""
{
if
r
.
Method
==
http
.
MethodGet
&&
r
.
ContentLength
==
0
&&
r
.
URL
.
RawQuery
==
""
{
return
}
if
code
,
err
:=
validateRequest
(
r
);
err
!=
nil
{
...
...
@@ -169,7 +169,7 @@ func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// validateRequest returns a non-zero response code and error message if the
// request is invalid.
func
validateRequest
(
r
*
http
.
Request
)
(
int
,
error
)
{
if
r
.
Method
==
"PUT"
||
r
.
Method
==
"DELETE"
{
if
r
.
Method
==
http
.
MethodPut
||
r
.
Method
==
http
.
MethodDelete
{
return
http
.
StatusMethodNotAllowed
,
errors
.
New
(
"method not allowed"
)
}
if
r
.
ContentLength
>
maxHTTPRequestContentLength
{
...
...
@@ -192,7 +192,7 @@ func newCorsHandler(srv *Server, allowedOrigins []string) http.Handler {
c
:=
cors
.
New
(
cors
.
Options
{
AllowedOrigins
:
allowedOrigins
,
AllowedMethods
:
[]
string
{
"POST"
,
"GET"
},
AllowedMethods
:
[]
string
{
http
.
MethodPost
,
http
.
MethodGet
},
MaxAge
:
600
,
AllowedHeaders
:
[]
string
{
"*"
},
})
...
...
This diff is collapsed.
Click to expand it.
rpc/http_test.go
+
5
−
5
View file @
f258a21a
...
...
@@ -24,25 +24,25 @@ import (
)
func
TestHTTPErrorResponseWithDelete
(
t
*
testing
.
T
)
{
testHTTPErrorResponse
(
t
,
"DELETE"
,
contentType
,
""
,
http
.
StatusMethodNotAllowed
)
testHTTPErrorResponse
(
t
,
http
.
MethodDelete
,
contentType
,
""
,
http
.
StatusMethodNotAllowed
)
}
func
TestHTTPErrorResponseWithPut
(
t
*
testing
.
T
)
{
testHTTPErrorResponse
(
t
,
"PUT"
,
contentType
,
""
,
http
.
StatusMethodNotAllowed
)
testHTTPErrorResponse
(
t
,
http
.
MethodPut
,
contentType
,
""
,
http
.
StatusMethodNotAllowed
)
}
func
TestHTTPErrorResponseWithMaxContentLength
(
t
*
testing
.
T
)
{
body
:=
make
([]
rune
,
maxHTTPRequestContentLength
+
1
)
testHTTPErrorResponse
(
t
,
"POST"
,
contentType
,
string
(
body
),
http
.
StatusRequestEntityTooLarge
)
http
.
MethodPost
,
contentType
,
string
(
body
),
http
.
StatusRequestEntityTooLarge
)
}
func
TestHTTPErrorResponseWithEmptyContentType
(
t
*
testing
.
T
)
{
testHTTPErrorResponse
(
t
,
"POST"
,
""
,
""
,
http
.
StatusUnsupportedMediaType
)
testHTTPErrorResponse
(
t
,
http
.
MethodPost
,
""
,
""
,
http
.
StatusUnsupportedMediaType
)
}
func
TestHTTPErrorResponseWithValidRequest
(
t
*
testing
.
T
)
{
testHTTPErrorResponse
(
t
,
"POST"
,
contentType
,
""
,
0
)
testHTTPErrorResponse
(
t
,
http
.
MethodPost
,
contentType
,
""
,
0
)
}
func
testHTTPErrorResponse
(
t
*
testing
.
T
,
method
,
contentType
,
body
string
,
expected
int
)
{
...
...
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