Skip to content

Commit 3b6e8a1

Browse files
committed
fix: error 415 on incorrect Content-Type, fixes #50
This matches the implicit and undocumented behavior on the IOHK cardano-submit-api software. Signed-off-by: Chris Gianelloni <[email protected]>
1 parent b7480b1 commit 3b6e8a1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

internal/api/api.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
// @title go-cardano-submit-api
2424
// @version 3.1.0
2525
// @description Cardano Submit API
26-
// @host localhost:8090
26+
// @host localhost
2727
// @Schemes http
2828
// @BasePath /
2929

@@ -116,12 +116,21 @@ func handleHealthcheck(c *gin.Context) {
116116
// @Param Content-Type header string true "Content type" Enums(application/cbor)
117117
// @Success 202 {object} string "Ok"
118118
// @Failure 400 {object} string "Bad Request"
119+
// @Failure 415 {object} string "Unsupported Media Type"
119120
// @Failure 500 {object} string "Server Error"
120121
// @Router /api/submit/tx [post]
121122
func handleSubmitTx(c *gin.Context) {
122123
// First, initialize our configuration and loggers
123124
cfg := config.GetConfig()
124125
logger := logging.GetLogger()
126+
// Check our headers for content-type
127+
if c.ContentType() != "application/cbor" {
128+
// Log the error, return an error to the user, and increment failed count
129+
logger.Errorf("invalid request body, should be application/cbor, got: %s", c.ContentType())
130+
c.String(415, "invalid request body, should be application/cbor")
131+
_ = ginmetrics.GetMonitor().GetMetric("tx_failure_count").Inc(nil)
132+
return
133+
}
125134
// Read raw transaction bytes from the request body and store in a byte array
126135
txRawBytes, err := ioutil.ReadAll(c.Request.Body)
127136
if err != nil {

0 commit comments

Comments
 (0)