@@ -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]
121122func 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