diff --git a/header.go b/header.go index f7483bf..b500163 100644 --- a/header.go +++ b/header.go @@ -1,9 +1,18 @@ package inertia const ( - HeaderInertia = "X-Inertia" - HeaderLocation = "X-Inertia-Location" - HeaderVersion = "X-Inertia-Version" + // HeaderInertia header. + HeaderInertia = "X-Inertia" + + // HeaderLocation header. + HeaderLocation = "X-Inertia-Location" + + // HeaderVersion header. + HeaderVersion = "X-Inertia-Version" + + // HeaderPartialComponent header. HeaderPartialComponent = "X-Inertia-Partial-Component" - HeaderPartialOnly = "X-Inertia-Partial-Data" + + // HeaderPartialOnly header. + HeaderPartialOnly = "X-Inertia-Partial-Data" ) diff --git a/inertia.go b/inertia.go index 3173137..70ea7ca 100644 --- a/inertia.go +++ b/inertia.go @@ -157,7 +157,7 @@ func (i *Inertia) Render(w http.ResponseWriter, r *http.Request, component strin } } - if i.isInertiaRequest(r) { + if r.Header.Get(HeaderInertia) != "" { js, err := json.Marshal(page) if err != nil { return err @@ -219,7 +219,7 @@ func (i *Inertia) Render(w http.ResponseWriter, r *http.Request, component strin // Location function. func (i *Inertia) Location(w http.ResponseWriter, r *http.Request, url string) { - if i.isInertiaRequest(r) { + if r.Header.Get(HeaderInertia) != "" { w.Header().Set(HeaderLocation, url) w.WriteHeader(http.StatusConflict) } else { @@ -227,10 +227,6 @@ func (i *Inertia) Location(w http.ResponseWriter, r *http.Request, url string) { } } -func (i *Inertia) isInertiaRequest(r *http.Request) bool { - return r.Header.Get(HeaderInertia) != "" -} - func (i *Inertia) createRootTemplate() (*template.Template, error) { if i.parsedTemplate != nil { return i.parsedTemplate, nil