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 baseURL = "https://chromium.googlesource.com/crashpad/crashpad/+/d oc/doc/generated/?format=TEXT" | |
Bons
2015/10/21 01:50:03
this can be
const (
baseURL = ...
bugBaseURL
Mark Mentovai
2015/10/21 01:53:41
Bons wrote:
| |
40 const bugBaseURL = "https://bugs.chromium.org/p/crashpad/" | |
41 | |
41 ctx := appengine.NewContext(r) | 42 ctx := appengine.NewContext(r) |
42 client := urlfetch.Client(ctx) | 43 client := urlfetch.Client(ctx) |
43 | 44 |
44 // Don’t show dotfiles. | 45 // Don’t show dotfiles. |
45 if strings.HasPrefix(path.Base(r.URL.Path), ".") { | 46 if strings.HasPrefix(path.Base(r.URL.Path), ".") { |
46 http.Error(w, http.StatusText(http.StatusNotFound), http.StatusN otFound) | 47 http.Error(w, http.StatusText(http.StatusNotFound), http.StatusN otFound) |
47 return | 48 return |
48 } | 49 } |
49 | 50 |
51 if r.URL.Path == "/bug" || r.URL.Path == "/bug/" { | |
52 http.Redirect(w, r, bugBaseURL, http.StatusFound) | |
53 return | |
54 } else if r.URL.Path == "/bug/new" { | |
55 http.Redirect(w, r, bugBaseURL+"issues/entry", http.StatusFound) | |
56 return | |
57 } else if strings.HasPrefix(r.URL.Path, "/bug/") { | |
58 http.Redirect(w, r, bugBaseURL+"issues/detail?id="+r.URL.Path[5: ], http.StatusFound) | |
59 return | |
60 } | |
61 | |
50 u, err := url.Parse(baseURL) | 62 u, err := url.Parse(baseURL) |
51 if err != nil { | 63 if err != nil { |
52 http.Error(w, err.Error(), http.StatusInternalServerError) | 64 http.Error(w, err.Error(), http.StatusInternalServerError) |
53 return | 65 return |
54 } | 66 } |
55 | 67 |
56 u.Path = path.Join(u.Path, r.URL.Path) | 68 u.Path = path.Join(u.Path, r.URL.Path) |
57 urlStr := u.String() | 69 urlStr := u.String() |
58 | 70 |
59 item, err := memcache.Get(ctx, urlStr) | 71 item, err := memcache.Get(ctx, urlStr) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 ".png": "image/png", | 125 ".png": "image/png", |
114 ".ico": "image/x-icon", | 126 ".ico": "image/x-icon", |
115 } | 127 } |
116 for suffix, typ := range contentTypes { | 128 for suffix, typ := range contentTypes { |
117 if strings.HasSuffix(file, suffix) { | 129 if strings.HasSuffix(file, suffix) { |
118 return typ | 130 return typ |
119 } | 131 } |
120 } | 132 } |
121 return "text/plain; charset=UTF-8" | 133 return "text/plain; charset=UTF-8" |
122 } | 134 } |
OLD | NEW |