2016-01-25 06:41:39 +01:00
|
|
|
// Copyright 2016 The Chihaya Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by the BSD 2-Clause license,
|
|
|
|
// which can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2016-03-02 22:15:48 +01:00
|
|
|
"github.com/chihaya/chihaya/config"
|
2016-01-25 06:41:39 +01:00
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type httpConfig struct {
|
2016-02-16 01:49:25 +01:00
|
|
|
Addr string `yaml:"addr"`
|
2016-02-27 21:19:13 +01:00
|
|
|
RequestTimeout time.Duration `yaml:"request_timeout"`
|
|
|
|
ReadTimeout time.Duration `yaml:"read_timeout"`
|
|
|
|
WriteTimeout time.Duration `yaml:"write_timeout"`
|
|
|
|
AllowIPSpoofing bool `yaml:"allow_ip_spoofing"`
|
|
|
|
DualStackedPeers bool `yaml:"dual_stacked_peers"`
|
|
|
|
RealIPHeader string `yaml:"real_ip_header"`
|
2016-01-25 06:41:39 +01:00
|
|
|
}
|
|
|
|
|
2016-03-02 22:15:48 +01:00
|
|
|
func newHTTPConfig(srvcfg *config.ServerConfig) (*httpConfig, error) {
|
|
|
|
bytes, err := yaml.Marshal(srvcfg.Config)
|
2016-01-25 06:41:39 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var cfg httpConfig
|
|
|
|
err = yaml.Unmarshal(bytes, &cfg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &cfg, nil
|
|
|
|
}
|