main.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. // Copyright (C) 2015 Audrius Butkevicius and Contributors (see the CONTRIBUTORS file).
  2. package main
  3. import (
  4. "compress/gzip"
  5. "context"
  6. "crypto/tls"
  7. "crypto/x509"
  8. "encoding/json"
  9. "flag"
  10. "fmt"
  11. "io"
  12. "io/ioutil"
  13. "log"
  14. "net"
  15. "net/http"
  16. "net/url"
  17. "os"
  18. "path/filepath"
  19. "strconv"
  20. "strings"
  21. "time"
  22. "github.com/syncthing/syncthing/lib/protocol"
  23. "github.com/golang/groupcache/lru"
  24. "github.com/oschwald/geoip2-golang"
  25. "github.com/prometheus/client_golang/prometheus"
  26. "github.com/prometheus/client_golang/prometheus/promhttp"
  27. "github.com/syncthing/syncthing/cmd/strelaypoolsrv/auto"
  28. "github.com/syncthing/syncthing/lib/assets"
  29. "github.com/syncthing/syncthing/lib/rand"
  30. "github.com/syncthing/syncthing/lib/relay/client"
  31. "github.com/syncthing/syncthing/lib/sync"
  32. "github.com/syncthing/syncthing/lib/tlsutil"
  33. "golang.org/x/time/rate"
  34. )
  35. type location struct {
  36. Latitude float64 `json:"latitude"`
  37. Longitude float64 `json:"longitude"`
  38. City string `json:"city"`
  39. Country string `json:"country"`
  40. Continent string `json:"continent"`
  41. }
  42. type relay struct {
  43. URL string `json:"url"`
  44. Location location `json:"location"`
  45. uri *url.URL
  46. Stats *stats `json:"stats"`
  47. StatsRetrieved time.Time `json:"statsRetrieved"`
  48. }
  49. type stats struct {
  50. StartTime time.Time `json:"startTime"`
  51. UptimeSeconds int `json:"uptimeSeconds"`
  52. PendingSessionKeys int `json:"numPendingSessionKeys"`
  53. ActiveSessions int `json:"numActiveSessions"`
  54. Connections int `json:"numConnections"`
  55. Proxies int `json:"numProxies"`
  56. BytesProxied int `json:"bytesProxied"`
  57. GoVersion string `json:"goVersion"`
  58. GoOS string `json:"goOS"`
  59. GoArch string `json:"goArch"`
  60. GoMaxProcs int `json:"goMaxProcs"`
  61. GoRoutines int `json:"goNumRoutine"`
  62. Rates []int64 `json:"kbps10s1m5m15m30m60m"`
  63. Options struct {
  64. NetworkTimeout int `json:"network-timeout"`
  65. PintInterval int `json:"ping-interval"`
  66. MessageTimeout int `json:"message-timeout"`
  67. SessionRate int `json:"per-session-rate"`
  68. GlobalRate int `json:"global-rate"`
  69. Pools []string `json:"pools"`
  70. ProvidedBy string `json:"provided-by"`
  71. } `json:"options"`
  72. }
  73. func (r relay) String() string {
  74. return r.URL
  75. }
  76. type request struct {
  77. relay *relay
  78. result chan result
  79. queueTimer *prometheus.Timer
  80. }
  81. type result struct {
  82. err error
  83. eviction time.Duration
  84. }
  85. var (
  86. testCert tls.Certificate
  87. knownRelaysFile = filepath.Join(os.TempDir(), "strelaypoolsrv_known_relays")
  88. listen = ":80"
  89. dir string
  90. evictionTime = time.Hour
  91. debug bool
  92. getLRUSize = 10 << 10
  93. getLimitBurst = 10
  94. getLimitAvg = 2
  95. postLRUSize = 1 << 10
  96. postLimitBurst = 2
  97. postLimitAvg = 2
  98. getLimit time.Duration
  99. postLimit time.Duration
  100. permRelaysFile string
  101. ipHeader string
  102. geoipPath string
  103. proto string
  104. statsRefresh = time.Minute / 2
  105. requestQueueLen = 10
  106. requestProcessors = 1
  107. getMut = sync.NewMutex()
  108. getLRUCache *lru.Cache
  109. postMut = sync.NewMutex()
  110. postLRUCache *lru.Cache
  111. requests chan request
  112. mut = sync.NewRWMutex()
  113. knownRelays = make([]*relay, 0)
  114. permanentRelays = make([]*relay, 0)
  115. evictionTimers = make(map[string]*time.Timer)
  116. )
  117. const (
  118. httpStatusEnhanceYourCalm = 429
  119. )
  120. func main() {
  121. log.SetOutput(os.Stdout)
  122. log.SetFlags(log.Lshortfile)
  123. flag.StringVar(&listen, "listen", listen, "Listen address")
  124. flag.StringVar(&dir, "keys", dir, "Directory where http-cert.pem and http-key.pem is stored for TLS listening")
  125. flag.BoolVar(&debug, "debug", debug, "Enable debug output")
  126. flag.DurationVar(&evictionTime, "eviction", evictionTime, "After how long the relay is evicted")
  127. flag.IntVar(&getLRUSize, "get-limit-cache", getLRUSize, "Get request limiter cache size")
  128. flag.IntVar(&getLimitAvg, "get-limit-avg", getLimitAvg, "Allowed average get request rate, per 10 s")
  129. flag.IntVar(&getLimitBurst, "get-limit-burst", getLimitBurst, "Allowed burst get requests")
  130. flag.IntVar(&postLRUSize, "post-limit-cache", postLRUSize, "Post request limiter cache size")
  131. flag.IntVar(&postLimitAvg, "post-limit-avg", postLimitAvg, "Allowed average post request rate, per minute")
  132. flag.IntVar(&postLimitBurst, "post-limit-burst", postLimitBurst, "Allowed burst post requests")
  133. flag.StringVar(&permRelaysFile, "perm-relays", "", "Path to list of permanent relays")
  134. flag.StringVar(&ipHeader, "ip-header", "", "Name of header which holds clients ip:port. Only meaningful when running behind a reverse proxy.")
  135. flag.StringVar(&geoipPath, "geoip", "GeoLite2-City.mmdb", "Path to GeoLite2-City database")
  136. flag.StringVar(&proto, "protocol", "tcp", "Protocol used for listening. 'tcp' for IPv4 and IPv6, 'tcp4' for IPv4, 'tcp6' for IPv6")
  137. flag.DurationVar(&statsRefresh, "stats-refresh", statsRefresh, "Interval at which to refresh relay stats")
  138. flag.IntVar(&requestQueueLen, "request-queue", requestQueueLen, "Queue length for incoming test requests")
  139. flag.IntVar(&requestProcessors, "request-processors", requestProcessors, "Number of request processor routines")
  140. flag.Parse()
  141. requests = make(chan request, requestQueueLen)
  142. getLimit = 10 * time.Second / time.Duration(getLimitAvg)
  143. postLimit = time.Minute / time.Duration(postLimitAvg)
  144. getLRUCache = lru.New(getLRUSize)
  145. postLRUCache = lru.New(postLRUSize)
  146. var listener net.Listener
  147. var err error
  148. if permRelaysFile != "" {
  149. permanentRelays = loadRelays(permRelaysFile)
  150. }
  151. testCert = createTestCertificate()
  152. for i := 0; i < requestProcessors; i++ {
  153. go requestProcessor()
  154. }
  155. // Load relays from cache in the background.
  156. // Load them in a serial fashion to make sure any genuine requests
  157. // are not dropped.
  158. go func() {
  159. for _, relay := range loadRelays(knownRelaysFile) {
  160. resultChan := make(chan result)
  161. requests <- request{relay, resultChan, nil}
  162. result := <-resultChan
  163. if result.err != nil {
  164. relayTestsTotal.WithLabelValues("failed").Inc()
  165. } else {
  166. relayTestsTotal.WithLabelValues("success").Inc()
  167. }
  168. }
  169. // Run the the stats refresher once the relays are loaded.
  170. statsRefresher(statsRefresh)
  171. }()
  172. if dir != "" {
  173. if debug {
  174. log.Println("Starting TLS listener on", listen)
  175. }
  176. certFile, keyFile := filepath.Join(dir, "http-cert.pem"), filepath.Join(dir, "http-key.pem")
  177. var cert tls.Certificate
  178. cert, err = tls.LoadX509KeyPair(certFile, keyFile)
  179. if err != nil {
  180. log.Fatalln("Failed to load HTTP X509 key pair:", err)
  181. }
  182. tlsCfg := &tls.Config{
  183. Certificates: []tls.Certificate{cert},
  184. MinVersion: tls.VersionTLS10, // No SSLv3
  185. ClientAuth: tls.RequestClientCert,
  186. CipherSuites: []uint16{
  187. // No RC4
  188. tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
  189. tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
  190. tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
  191. tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
  192. tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
  193. tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
  194. tls.TLS_RSA_WITH_AES_128_CBC_SHA,
  195. tls.TLS_RSA_WITH_AES_256_CBC_SHA,
  196. tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
  197. tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
  198. },
  199. }
  200. listener, err = tls.Listen(proto, listen, tlsCfg)
  201. } else {
  202. if debug {
  203. log.Println("Starting plain listener on", listen)
  204. }
  205. listener, err = net.Listen(proto, listen)
  206. }
  207. if err != nil {
  208. log.Fatalln("listen:", err)
  209. }
  210. handler := http.NewServeMux()
  211. handler.HandleFunc("/", handleAssets)
  212. handler.HandleFunc("/endpoint", handleRequest)
  213. handler.HandleFunc("/metrics", handleMetrics)
  214. srv := http.Server{
  215. Handler: handler,
  216. ReadTimeout: 10 * time.Second,
  217. }
  218. err = srv.Serve(listener)
  219. if err != nil {
  220. log.Fatalln("serve:", err)
  221. }
  222. }
  223. func handleMetrics(w http.ResponseWriter, r *http.Request) {
  224. timer := prometheus.NewTimer(metricsRequestsSeconds)
  225. // Acquire the mutex just to make sure we're not caught mid-way stats collection
  226. mut.RLock()
  227. promhttp.Handler().ServeHTTP(w, r)
  228. mut.RUnlock()
  229. timer.ObserveDuration()
  230. }
  231. func handleAssets(w http.ResponseWriter, r *http.Request) {
  232. w.Header().Set("Cache-Control", "no-cache, must-revalidate")
  233. path := r.URL.Path[1:]
  234. if path == "" {
  235. path = "index.html"
  236. }
  237. as, ok := auto.Assets()[path]
  238. if !ok {
  239. w.WriteHeader(http.StatusNotFound)
  240. return
  241. }
  242. assets.Serve(w, r, as)
  243. }
  244. func handleRequest(w http.ResponseWriter, r *http.Request) {
  245. timer := prometheus.NewTimer(apiRequestsSeconds.WithLabelValues(r.Method))
  246. w = NewLoggingResponseWriter(w)
  247. defer func() {
  248. timer.ObserveDuration()
  249. lw := w.(*loggingResponseWriter)
  250. apiRequestsTotal.WithLabelValues(r.Method, strconv.Itoa(lw.statusCode)).Inc()
  251. }()
  252. if ipHeader != "" {
  253. r.RemoteAddr = r.Header.Get(ipHeader)
  254. }
  255. w.Header().Set("Access-Control-Allow-Origin", "*")
  256. switch r.Method {
  257. case "GET":
  258. if limit(r.RemoteAddr, getLRUCache, getMut, getLimit, getLimitBurst) {
  259. w.WriteHeader(httpStatusEnhanceYourCalm)
  260. return
  261. }
  262. handleGetRequest(w, r)
  263. case "POST":
  264. if limit(r.RemoteAddr, postLRUCache, postMut, postLimit, postLimitBurst) {
  265. w.WriteHeader(httpStatusEnhanceYourCalm)
  266. return
  267. }
  268. handlePostRequest(w, r)
  269. default:
  270. if debug {
  271. log.Println("Unhandled HTTP method", r.Method)
  272. }
  273. http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
  274. }
  275. }
  276. func handleGetRequest(rw http.ResponseWriter, r *http.Request) {
  277. rw.Header().Set("Content-Type", "application/json; charset=utf-8")
  278. mut.RLock()
  279. relays := make([]*relay, len(permanentRelays)+len(knownRelays))
  280. n := copy(relays, permanentRelays)
  281. copy(relays[n:], knownRelays)
  282. mut.RUnlock()
  283. // Shuffle
  284. rand.Shuffle(relays)
  285. w := io.Writer(rw)
  286. if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
  287. rw.Header().Set("Content-Encoding", "gzip")
  288. gw := gzip.NewWriter(rw)
  289. defer gw.Close()
  290. w = gw
  291. }
  292. _ = json.NewEncoder(w).Encode(map[string][]*relay{
  293. "relays": relays,
  294. })
  295. }
  296. func handlePostRequest(w http.ResponseWriter, r *http.Request) {
  297. var relayCert *x509.Certificate
  298. if r.TLS != nil && len(r.TLS.PeerCertificates) > 0 {
  299. relayCert = r.TLS.PeerCertificates[0]
  300. log.Printf("Got TLS cert from relay server")
  301. }
  302. var newRelay relay
  303. err := json.NewDecoder(r.Body).Decode(&newRelay)
  304. r.Body.Close()
  305. if err != nil {
  306. if debug {
  307. log.Println("Failed to parse payload")
  308. }
  309. http.Error(w, err.Error(), http.StatusBadRequest)
  310. return
  311. }
  312. uri, err := url.Parse(newRelay.URL)
  313. if err != nil {
  314. if debug {
  315. log.Println("Failed to parse URI", newRelay.URL)
  316. }
  317. http.Error(w, err.Error(), http.StatusBadRequest)
  318. return
  319. }
  320. if relayCert != nil {
  321. advertisedId := uri.Query().Get("id")
  322. idFromCert := protocol.NewDeviceID(relayCert.Raw).String()
  323. if advertisedId != idFromCert {
  324. log.Println("Warning: Relay server requested to join with an ID different from the join request, rejecting")
  325. http.Error(w, "mismatched advertised id and join request cert", http.StatusBadRequest)
  326. return
  327. }
  328. }
  329. host, port, err := net.SplitHostPort(uri.Host)
  330. if err != nil {
  331. if debug {
  332. log.Println("Failed to split URI", newRelay.URL)
  333. }
  334. http.Error(w, err.Error(), http.StatusBadRequest)
  335. return
  336. }
  337. // Get the IP address of the client
  338. rhost := r.RemoteAddr
  339. if host, _, err := net.SplitHostPort(rhost); err == nil {
  340. rhost = host
  341. }
  342. ip := net.ParseIP(host)
  343. // The client did not provide an IP address, use the IP address of the client.
  344. if ip == nil || ip.IsUnspecified() {
  345. uri.Host = net.JoinHostPort(rhost, port)
  346. newRelay.URL = uri.String()
  347. } else if host != rhost && relayCert == nil {
  348. if debug {
  349. log.Println("IP address advertised does not match client IP address", r.RemoteAddr, uri)
  350. }
  351. http.Error(w, fmt.Sprintf("IP advertised %s does not match client IP %s", host, rhost), http.StatusUnauthorized)
  352. return
  353. }
  354. newRelay.uri = uri
  355. for _, current := range permanentRelays {
  356. if current.uri.Host == newRelay.uri.Host {
  357. if debug {
  358. log.Println("Asked to add a relay", newRelay, "which exists in permanent list")
  359. }
  360. http.Error(w, "Invalid request", http.StatusBadRequest)
  361. return
  362. }
  363. }
  364. reschan := make(chan result)
  365. select {
  366. case requests <- request{&newRelay, reschan, prometheus.NewTimer(relayTestActionsSeconds.WithLabelValues("queue"))}:
  367. result := <-reschan
  368. if result.err != nil {
  369. relayTestsTotal.WithLabelValues("failed").Inc()
  370. http.Error(w, result.err.Error(), http.StatusBadRequest)
  371. return
  372. }
  373. relayTestsTotal.WithLabelValues("success").Inc()
  374. w.Header().Set("Content-Type", "application/json; charset=utf-8")
  375. json.NewEncoder(w).Encode(map[string]time.Duration{
  376. "evictionIn": result.eviction,
  377. })
  378. default:
  379. relayTestsTotal.WithLabelValues("dropped").Inc()
  380. if debug {
  381. log.Println("Dropping request")
  382. }
  383. w.WriteHeader(httpStatusEnhanceYourCalm)
  384. }
  385. }
  386. func requestProcessor() {
  387. for request := range requests {
  388. if request.queueTimer != nil {
  389. request.queueTimer.ObserveDuration()
  390. }
  391. timer := prometheus.NewTimer(relayTestActionsSeconds.WithLabelValues("test"))
  392. handleRelayTest(request)
  393. timer.ObserveDuration()
  394. }
  395. }
  396. func handleRelayTest(request request) {
  397. if debug {
  398. log.Println("Request for", request.relay)
  399. }
  400. if err := client.TestRelay(context.TODO(), request.relay.uri, []tls.Certificate{testCert}, time.Second, 2*time.Second, 3); err != nil {
  401. if debug {
  402. log.Println("Test for relay", request.relay, "failed:", err)
  403. }
  404. request.result <- result{err, 0}
  405. return
  406. }
  407. stats := fetchStats(request.relay)
  408. location := getLocation(request.relay.uri.Host)
  409. mut.Lock()
  410. if stats != nil {
  411. updateMetrics(request.relay.uri.Host, *stats, location)
  412. }
  413. request.relay.Stats = stats
  414. request.relay.StatsRetrieved = time.Now().Truncate(time.Second)
  415. request.relay.Location = location
  416. timer, ok := evictionTimers[request.relay.uri.Host]
  417. if ok {
  418. if debug {
  419. log.Println("Stopping existing timer for", request.relay)
  420. }
  421. timer.Stop()
  422. }
  423. for i, current := range knownRelays {
  424. if current.uri.Host == request.relay.uri.Host {
  425. if debug {
  426. log.Println("Relay", request.relay, "already exists")
  427. }
  428. // Evict the old entry anyway, as configuration might have changed.
  429. last := len(knownRelays) - 1
  430. knownRelays[i] = knownRelays[last]
  431. knownRelays = knownRelays[:last]
  432. goto found
  433. }
  434. }
  435. if debug {
  436. log.Println("Adding new relay", request.relay)
  437. }
  438. found:
  439. knownRelays = append(knownRelays, request.relay)
  440. evictionTimers[request.relay.uri.Host] = time.AfterFunc(evictionTime, evict(request.relay))
  441. mut.Unlock()
  442. if err := saveRelays(knownRelaysFile, knownRelays); err != nil {
  443. log.Println("Failed to write known relays: " + err.Error())
  444. }
  445. request.result <- result{nil, evictionTime}
  446. }
  447. func evict(relay *relay) func() {
  448. return func() {
  449. mut.Lock()
  450. defer mut.Unlock()
  451. if debug {
  452. log.Println("Evicting", relay)
  453. }
  454. for i, current := range knownRelays {
  455. if current.uri.Host == relay.uri.Host {
  456. if debug {
  457. log.Println("Evicted", relay)
  458. }
  459. last := len(knownRelays) - 1
  460. knownRelays[i] = knownRelays[last]
  461. knownRelays = knownRelays[:last]
  462. deleteMetrics(current.uri.Host)
  463. }
  464. }
  465. delete(evictionTimers, relay.uri.Host)
  466. }
  467. }
  468. func limit(addr string, cache *lru.Cache, lock sync.Mutex, intv time.Duration, burst int) bool {
  469. if host, _, err := net.SplitHostPort(addr); err == nil {
  470. addr = host
  471. }
  472. lock.Lock()
  473. v, _ := cache.Get(addr)
  474. bkt, ok := v.(*rate.Limiter)
  475. if !ok {
  476. bkt = rate.NewLimiter(rate.Every(intv), burst)
  477. cache.Add(addr, bkt)
  478. }
  479. lock.Unlock()
  480. return !bkt.Allow()
  481. }
  482. func loadRelays(file string) []*relay {
  483. content, err := ioutil.ReadFile(file)
  484. if err != nil {
  485. log.Println("Failed to load relays: " + err.Error())
  486. return nil
  487. }
  488. var relays []*relay
  489. for _, line := range strings.Split(string(content), "\n") {
  490. if len(line) == 0 {
  491. continue
  492. }
  493. uri, err := url.Parse(line)
  494. if err != nil {
  495. if debug {
  496. log.Println("Skipping relay", line, "due to parse error", err)
  497. }
  498. continue
  499. }
  500. relays = append(relays, &relay{
  501. URL: line,
  502. Location: getLocation(uri.Host),
  503. uri: uri,
  504. })
  505. if debug {
  506. log.Println("Adding relay", line)
  507. }
  508. }
  509. return relays
  510. }
  511. func saveRelays(file string, relays []*relay) error {
  512. var content string
  513. for _, relay := range relays {
  514. content += relay.uri.String() + "\n"
  515. }
  516. return ioutil.WriteFile(file, []byte(content), 0777)
  517. }
  518. func createTestCertificate() tls.Certificate {
  519. tmpDir, err := ioutil.TempDir("", "relaypoolsrv")
  520. if err != nil {
  521. log.Fatal(err)
  522. }
  523. certFile, keyFile := filepath.Join(tmpDir, "cert.pem"), filepath.Join(tmpDir, "key.pem")
  524. cert, err := tlsutil.NewCertificate(certFile, keyFile, "relaypoolsrv", 20*365)
  525. if err != nil {
  526. log.Fatalln("Failed to create test X509 key pair:", err)
  527. }
  528. return cert
  529. }
  530. func getLocation(host string) location {
  531. timer := prometheus.NewTimer(locationLookupSeconds)
  532. defer timer.ObserveDuration()
  533. db, err := geoip2.Open(geoipPath)
  534. if err != nil {
  535. return location{}
  536. }
  537. defer db.Close()
  538. addr, err := net.ResolveTCPAddr("tcp", host)
  539. if err != nil {
  540. return location{}
  541. }
  542. city, err := db.City(addr.IP)
  543. if err != nil {
  544. return location{}
  545. }
  546. return location{
  547. Longitude: city.Location.Longitude,
  548. Latitude: city.Location.Latitude,
  549. City: city.City.Names["en"],
  550. Country: city.Country.IsoCode,
  551. Continent: city.Continent.Code,
  552. }
  553. }
  554. type loggingResponseWriter struct {
  555. http.ResponseWriter
  556. statusCode int
  557. }
  558. func NewLoggingResponseWriter(w http.ResponseWriter) *loggingResponseWriter {
  559. return &loggingResponseWriter{w, http.StatusOK}
  560. }
  561. func (lrw *loggingResponseWriter) WriteHeader(code int) {
  562. lrw.statusCode = code
  563. lrw.ResponseWriter.WriteHeader(code)
  564. }