mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-26 23:01:05 +08:00
Add app engine app to mirror html docs from chromium.googlesource.com
BUG=crashpad:67 R=mark@chromium.org, rsesek@chromium.org Review URL: https://codereview.chromium.org/1393353002 . Patch from Andrew Bonventre <andybons@chromium.org>.
This commit is contained in:
parent
2bee026ca1
commit
a2740b23a2
9
doc/appengine/app.yaml
Normal file
9
doc/appengine/app.yaml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
application: crashpad-home
|
||||||
|
version: 1
|
||||||
|
runtime: go
|
||||||
|
api_version: go1
|
||||||
|
|
||||||
|
handlers:
|
||||||
|
- url: /.*
|
||||||
|
script: _go_app
|
||||||
|
secure: always
|
122
doc/appengine/main.go
Normal file
122
doc/appengine/main.go
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
// Copyright 2015 The Crashpad Authors. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// Package crashpad mirrors crashpad documentation from Chromium’s git repo.
|
||||||
|
package crashpad
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/appengine"
|
||||||
|
"google.golang.org/appengine/memcache"
|
||||||
|
"google.golang.org/appengine/urlfetch"
|
||||||
|
)
|
||||||
|
|
||||||
|
const baseURL = "https://chromium.googlesource.com/crashpad/crashpad/+/doc/doc/generated/?format=TEXT"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
http.HandleFunc("/", handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
ctx := appengine.NewContext(r)
|
||||||
|
client := urlfetch.Client(ctx)
|
||||||
|
|
||||||
|
// Don’t show dotfiles.
|
||||||
|
if strings.HasPrefix(path.Base(r.URL.Path), ".") {
|
||||||
|
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := url.Parse(baseURL)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
u.Path = path.Join(u.Path, r.URL.Path)
|
||||||
|
urlStr := u.String()
|
||||||
|
|
||||||
|
item, err := memcache.Get(ctx, urlStr)
|
||||||
|
if err == memcache.ErrCacheMiss {
|
||||||
|
resp, err := client.Get(urlStr)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
w.WriteHeader(resp.StatusCode)
|
||||||
|
for k, v := range w.Header() {
|
||||||
|
w.Header()[k] = v
|
||||||
|
}
|
||||||
|
io.Copy(w, resp.Body)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirect directories to their index pages (/doc/ -> /doc/index.html).
|
||||||
|
if resp.Header.Get("X-Gitiles-Object-Type") == "tree" {
|
||||||
|
http.Redirect(w, r, path.Join(r.URL.Path, "/index.html"), http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
decoder := base64.NewDecoder(base64.StdEncoding, resp.Body)
|
||||||
|
b, err := ioutil.ReadAll(decoder)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
item = &memcache.Item{
|
||||||
|
Key: urlStr,
|
||||||
|
Value: b,
|
||||||
|
Expiration: 1 * time.Hour,
|
||||||
|
}
|
||||||
|
if err := memcache.Set(ctx, item); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", contentType(path.Base(u.Path)))
|
||||||
|
fmt.Fprintf(w, "%s", item.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// contentType returns the appropriate content type header for file.
|
||||||
|
func contentType(file string) string {
|
||||||
|
contentTypes := map[string]string{
|
||||||
|
".html": "text/html; charset=UTF-8",
|
||||||
|
".css": "text/css; charset=UTF-8",
|
||||||
|
".js": "text/javascript; charset=UTF-8",
|
||||||
|
".png": "image/png",
|
||||||
|
".ico": "image/x-icon",
|
||||||
|
}
|
||||||
|
for suffix, typ := range contentTypes {
|
||||||
|
if strings.HasSuffix(file, suffix) {
|
||||||
|
return typ
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "text/plain; charset=UTF-8"
|
||||||
|
}
|
BIN
doc/favicon.ico
Normal file
BIN
doc/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
@ -50,6 +50,9 @@ ${sed_ext} -e 's%<a href="([^/]+)\.html">%<a href="doc/\1.html">%g' \
|
|||||||
< "${output_dir}/doc/index.html" > "${output_dir}/index.html"
|
< "${output_dir}/doc/index.html" > "${output_dir}/index.html"
|
||||||
rm "${output_dir}/doc/index.html"
|
rm "${output_dir}/doc/index.html"
|
||||||
|
|
||||||
|
# Ensure a favicon exists at the root since the browser will always request it.
|
||||||
|
cp doc/favicon.ico "${output_dir}/"
|
||||||
|
|
||||||
# Create man/index.html
|
# Create man/index.html
|
||||||
cd "${output_dir}/man"
|
cd "${output_dir}/man"
|
||||||
cat > index.html << __EOF__
|
cat > index.html << __EOF__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user