Vivek
Vivek

Reputation: 13288

gin - problem accessing url-encoded path-param containing forward slash

For a given route with path param (example below)

router.GET("/employee/:id", empHandler.GetEmployee)

When tried to invoke the url with id path-param(encoded) containing forward slashes

id = 21/admin/527

url-encoded id = 21%2Fadmin%2F527

https://localhost:8000/emplayee/21%2Fadmin%2F527

I'm getting 404 when I try to hit this request It seems that gin is automatically decoding the path param and forming a route with url containing decoded path-param

https://localhost:8000/emplayee/21/admin/527

I want the exact encoded value for employee id path-param since it is to be used for calling other api which requires it to be url-encoded.

Upvotes: 5

Views: 2693

Answers (1)

Vivek
Vivek

Reputation: 13288

I've resolved this issue by configuring the router with below options

router.UseRawPath = true
router.UnescapePathValues = false

This resolved the 404 error, also gin context return the same encoded(unescaped) value. This value can now be used to call the other APIs which requires url-encoded(unescaped) value for employee id

Upvotes: 7

Related Questions