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 13 matching lines...) Expand all Loading... |
24 "net/url" | 24 "net/url" |
25 "path" | 25 "path" |
26 "strings" | 26 "strings" |
27 "time" | 27 "time" |
28 | 28 |
29 "google.golang.org/appengine" | 29 "google.golang.org/appengine" |
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 const baseURL = "https://chromium.googlesource.com/crashpad/crashpad/+/doc/doc/g
enerated/?format=TEXT" | |
35 | |
36 func init() { | 34 func init() { |
37 http.HandleFunc("/", handler) | 35 http.HandleFunc("/", handler) |
38 } | 36 } |
39 | 37 |
40 func handler(w http.ResponseWriter, r *http.Request) { | 38 func handler(w http.ResponseWriter, r *http.Request) { |
| 39 const ( |
| 40 baseURL = "https://chromium.googlesource.com/crashpad/crashpa
d/+/doc/doc/generated/?format=TEXT" |
| 41 bugBaseURL = "https://bugs.chromium.org/p/crashpad/" |
| 42 ) |
| 43 |
41 ctx := appengine.NewContext(r) | 44 ctx := appengine.NewContext(r) |
42 client := urlfetch.Client(ctx) | 45 client := urlfetch.Client(ctx) |
43 | 46 |
44 // Don’t show dotfiles. | 47 // Don’t show dotfiles. |
45 if strings.HasPrefix(path.Base(r.URL.Path), ".") { | 48 if strings.HasPrefix(path.Base(r.URL.Path), ".") { |
46 http.Error(w, http.StatusText(http.StatusNotFound), http.StatusN
otFound) | 49 http.Error(w, http.StatusText(http.StatusNotFound), http.StatusN
otFound) |
47 return | 50 return |
48 } | 51 } |
49 | 52 |
| 53 if r.URL.Path == "/bug" || r.URL.Path == "/bug/" { |
| 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 |
50 u, err := url.Parse(baseURL) | 64 u, err := url.Parse(baseURL) |
51 if err != nil { | 65 if err != nil { |
52 http.Error(w, err.Error(), http.StatusInternalServerError) | 66 http.Error(w, err.Error(), http.StatusInternalServerError) |
53 return | 67 return |
54 } | 68 } |
55 | 69 |
56 u.Path = path.Join(u.Path, r.URL.Path) | 70 u.Path = path.Join(u.Path, r.URL.Path) |
57 urlStr := u.String() | 71 urlStr := u.String() |
58 | 72 |
59 item, err := memcache.Get(ctx, urlStr) | 73 item, err := memcache.Get(ctx, urlStr) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 ".png": "image/png", | 127 ".png": "image/png", |
114 ".ico": "image/x-icon", | 128 ".ico": "image/x-icon", |
115 } | 129 } |
116 for suffix, typ := range contentTypes { | 130 for suffix, typ := range contentTypes { |
117 if strings.HasSuffix(file, suffix) { | 131 if strings.HasSuffix(file, suffix) { |
118 return typ | 132 return typ |
119 } | 133 } |
120 } | 134 } |
121 return "text/plain; charset=UTF-8" | 135 return "text/plain; charset=UTF-8" |
122 } | 136 } |
OLD | NEW |