# Get dan Set Header

Untuk request header di Gin bisa menggunakan method GetHeader() dan untuk set header baru di response bisa menggunakan method Header(). Contohnya seperti _code_ dibawah ini.

```go
package main
import (
	"fmt"
	"net/http"
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	r.GET("/", TestHeader)
	r.Run(":5000")
}

func TestHeader(ctx *gin.Context) {
	// Get header dari request
	testHeader := ctx.GetHeader("Content-Type")
	// Set new header in response
	ctx.Header("Content-Type", "application/xml")
	ctx.Header("Content-Type", "application/json")
	ctx.Header("Test", "test")
	// Get header from response
	getResHeader := ctx.Writer.Header().Get("Content-Type")
	fmt.Println(getResHeader)
	ctx.JSON(200, gin.H{
		"status": http.StatusOK,
		"header": testHeader,
	})
}
```

<figure><img src="https://1578455751-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F09pucuEBc5BTaaur3uoo%2Fuploads%2FqzO68xxQk1ltf2EEoD0k%2F1.png?alt=media&#x26;token=2db364d5-4d33-4a75-8d1d-2fb6a3c30c1c" alt=""><figcaption></figcaption></figure>
