OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 19 matching lines...) Expand all Loading... |
30 "google.golang.org/appengine/memcache" | 30 "google.golang.org/appengine/memcache" |
31 "google.golang.org/appengine/urlfetch" | 31 "google.golang.org/appengine/urlfetch" |
32 ) | 32 ) |
33 | 33 |
34 func init() { | 34 func init() { |
35 http.HandleFunc("/", handler) | 35 http.HandleFunc("/", handler) |
36 } | 36 } |
37 | 37 |
38 func handler(w http.ResponseWriter, r *http.Request) { | 38 func handler(w http.ResponseWriter, r *http.Request) { |
39 const ( | 39 const ( |
40 » » baseURL = "https://chromium.googlesource.com/crashpad/crashpa
d/+/doc/doc/generated/?format=TEXT" | 40 » » baseURL = "https://chromium.googlesource.com/crashpa
d/crashpad/+/" |
41 » » bugBaseURL = "https://bugs.chromium.org/p/crashpad/" | 41 » » masterBaseURL = baseURL + "master/" |
| 42 » » generatedDocBaseURL = baseURL + "doc/doc/generated/?format=TEXT" |
| 43 » » bugBaseURL = "https://bugs.chromium.org/p/crashpad/" |
42 ) | 44 ) |
43 | 45 |
| 46 redirectMap := map[string]string{ |
| 47 "/": masterBaseURL + "README.md", |
| 48 "/bug": bugBaseURL, |
| 49 "/bug/": bugBaseURL, |
| 50 "/bug/new": bugBaseURL + "issues/entry", |
| 51 "/doc/developing.html": masterBaseURL + "/doc/develo
ping.md", |
| 52 "/doc/status.html": masterBaseURL + "/doc/status
.md", |
| 53 "/index.html": masterBaseURL + "README.md", |
| 54 "/man": masterBaseURL + "doc/man.md"
, |
| 55 "/man/": masterBaseURL + "doc/man.md"
, |
| 56 "/man/catch_exception_tool.html": masterBaseURL + "tools/mac/c
atch_exception_tool.md", |
| 57 "/man/crashpad_database_util.html": masterBaseURL + "tools/crash
pad_database_util.md", |
| 58 "/man/crashpad_handler.html": masterBaseURL + "handler/cra
shpad_handler.md", |
| 59 "/man/exception_port_tool.html": masterBaseURL + "tools/mac/e
xception_port_tool.md", |
| 60 "/man/generate_dump.html": masterBaseURL + "tools/gener
ate_dump.md", |
| 61 "/man/index.html": masterBaseURL + "doc/man.md"
, |
| 62 "/man/on_demand_service_tool.html": masterBaseURL + "tools/mac/o
n_demand_service_tool.md", |
| 63 "/man/run_with_crashpad.html": masterBaseURL + "tools/mac/r
un_with_crashpad.md", |
| 64 } |
| 65 |
44 ctx := appengine.NewContext(r) | 66 ctx := appengine.NewContext(r) |
45 client := urlfetch.Client(ctx) | 67 client := urlfetch.Client(ctx) |
46 | 68 |
| 69 destinationURL, exists := redirectMap[r.URL.Path] |
| 70 if exists { |
| 71 http.Redirect(w, r, destinationURL, http.StatusFound) |
| 72 return |
| 73 } |
| 74 |
| 75 if strings.HasPrefix(r.URL.Path, "/bug/") { |
| 76 http.Redirect(w, r, bugBaseURL+"issues/detail?id="+r.URL.Path[5:
], http.StatusFound) |
| 77 return |
| 78 } |
| 79 |
47 // Don’t show dotfiles. | 80 // Don’t show dotfiles. |
48 if strings.HasPrefix(path.Base(r.URL.Path), ".") { | 81 if strings.HasPrefix(path.Base(r.URL.Path), ".") { |
49 http.Error(w, http.StatusText(http.StatusNotFound), http.StatusN
otFound) | 82 http.Error(w, http.StatusText(http.StatusNotFound), http.StatusN
otFound) |
50 return | 83 return |
51 } | 84 } |
52 | 85 |
53 » if r.URL.Path == "/bug" || r.URL.Path == "/bug/" { | 86 » u, err := url.Parse(generatedDocBaseURL) |
54 » » http.Redirect(w, r, bugBaseURL, http.StatusFound) | |
55 » » return | |
56 » } else if r.URL.Path == "/bug/new" { | |
57 » » http.Redirect(w, r, bugBaseURL+"issues/entry", http.StatusFound) | |
58 » » return | |
59 » } else if strings.HasPrefix(r.URL.Path, "/bug/") { | |
60 » » http.Redirect(w, r, bugBaseURL+"issues/detail?id="+r.URL.Path[5:
], http.StatusFound) | |
61 » » return | |
62 » } | |
63 | |
64 » u, err := url.Parse(baseURL) | |
65 if err != nil { | 87 if err != nil { |
66 http.Error(w, err.Error(), http.StatusInternalServerError) | 88 http.Error(w, err.Error(), http.StatusInternalServerError) |
67 return | 89 return |
68 } | 90 } |
69 | 91 |
70 u.Path = path.Join(u.Path, r.URL.Path) | 92 u.Path = path.Join(u.Path, r.URL.Path) |
71 urlStr := u.String() | 93 urlStr := u.String() |
72 | 94 |
73 item, err := memcache.Get(ctx, urlStr) | 95 item, err := memcache.Get(ctx, urlStr) |
74 if err == memcache.ErrCacheMiss { | 96 if err == memcache.ErrCacheMiss { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 ".png": "image/png", | 149 ".png": "image/png", |
128 ".ico": "image/x-icon", | 150 ".ico": "image/x-icon", |
129 } | 151 } |
130 for suffix, typ := range contentTypes { | 152 for suffix, typ := range contentTypes { |
131 if strings.HasSuffix(file, suffix) { | 153 if strings.HasSuffix(file, suffix) { |
132 return typ | 154 return typ |
133 } | 155 } |
134 } | 156 } |
135 return "text/plain; charset=UTF-8" | 157 return "text/plain; charset=UTF-8" |
136 } | 158 } |
OLD | NEW |