Skip to content

Commit

Permalink
server: serve pdf content
Browse files Browse the repository at this point in the history
Fixes #14
  • Loading branch information
changkun committed May 1, 2022
1 parent bb30095 commit 84dcba1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions short.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ func (s *server) sHandlerGet(w http.ResponseWriter, r *http.Request) {
}
}

// If this is a page that refers to a PDF, we prefer serve it as a PDF
// content directly rather than redirect.
if strings.HasSuffix(red.URL, ".pdf") {
resp, err := http.Get(red.URL)
if err != nil {
return
}
defer resp.Body.Close()

_, err = io.Copy(w, resp.Body)
return
}

// Finally, let's redirect!
http.Redirect(w, r, red.URL, http.StatusTemporaryRedirect)
}
Expand Down

0 comments on commit 84dcba1

Please sign in to comment.