Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
petaki committed Feb 14, 2025
2 parents 73bfe20 + 2fcdd77 commit fe16f35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
17 changes: 13 additions & 4 deletions header.go
Original file line number Diff line number Diff line change
@@ -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"
)
8 changes: 2 additions & 6 deletions inertia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -219,18 +219,14 @@ 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 {
http.Redirect(w, r, url, http.StatusFound)
}
}

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
Expand Down

0 comments on commit fe16f35

Please sign in to comment.