Skip to content

Commit

Permalink
Update response.go
Browse files Browse the repository at this point in the history
Add CSS and JS content type
  • Loading branch information
susarlanikhilesh authored Jul 16, 2024
1 parent b984460 commit 60a69b9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ func (ctx *RequestCtx) HTTPResponseBytes(body []byte, statusCode ...int) error {
return nil
}

// CSSResponseBytes returns response with body in css format.
func (ctx *RequestCtx) CSSResponseBytes(body []byte, statusCode ...int) error {
ctx.Response.Header.SetContentType("text/css; charset=utf-8")

if len(statusCode) > 0 {
ctx.Response.Header.SetStatusCode(statusCode[0])
}

ctx.Response.SetBody(body)

return nil
}

// JSResponseBytes returns response with body in javascript format.
func (ctx *RequestCtx) JSResponseBytes(body []byte, statusCode ...int) error {
ctx.Response.Header.SetContentType("application/javascript")

if len(statusCode) > 0 {
ctx.Response.Header.SetStatusCode(statusCode[0])
}

ctx.Response.SetBody(body)

return nil
}

// TextResponse return response with body in text format.
func (ctx *RequestCtx) TextResponse(body string, statusCode ...int) error {
ctx.Response.Header.SetContentType("text/plain; charset=utf-8")
Expand Down

0 comments on commit 60a69b9

Please sign in to comment.