<commit_before>package knuckles

import (
  "fmt"
  "io"
  "log"
  "net"
  "net/http"
  "net/url"
  "strconv"
  "strings"
  "time"
)

type HTTPProxyConfig struct {
  XForwardedFor         bool
  XRequestStart         bool
  XForwardedProto       string
  Store                 Store
  Addr                  string
  RedirectNoHostname    string
  RedirectNoBackend     string
  RedirectInternalError string
}

type HTTPProxy struct {
  Server   http.Server
  listener net.Listener
  Config   HTTPProxyConfig
}

func NewHTTPProxy(config HTTPProxyConfig) (*HTTPProxy, error) {
  h := &HTTPProxy{
    Config: config,
  }

  mux := http.NewServeMux()
  mux.Handle("/", h)
  h.Server.Handler = mux

  return h, nil
}

func (h *HTTPProxy) Start() error {
  var err error

  h.listener, err = net.Listen("tcp", h.Config.Addr)
  if err != nil {
    return err
  }

  return h.Server.Serve(h.listener)
}

func (h *HTTPProxy) Stop() error {
  return h.listener.Close()
}

func (h *HTTPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  hostname := r.Host
  log.Println("Request for", hostname)

  if sep := strings.Index(hostname, ":"); sep >= 0 {
    hostname = hostname[:sep]
  }

  // tag before starting redis queries
  if h.Config.XRequestStart {
    r.Header.Set("X-Request-Start", requestStart())
  }

  if h.Config.XForwardedProto != "" {
    r.Header.Set("X-Forwarded-Proto", h.Config.XForwardedProto)
  }

  if h.Config.XForwardedFor {
    r.Header.Set("X-Forwarded-For", clientIP(r))
  }<commit_msg>removing useless log<commit_after>package knuckles

import (
  "fmt"
  "io"
  "net"
  "net/http"
  "net/url"
  "strconv"
  "strings"
  "time"
)

type HTTPProxyConfig struct {
  XForwardedFor         bool
  XRequestStart         bool
  XForwardedProto       string
  Store                 Store
  Addr                  string
  RedirectNoHostname    string
  RedirectNoBackend     string
  RedirectInternalError string
}

type HTTPProxy struct {
  Server   http.Server
  listener net.Listener
  Config   HTTPProxyConfig
}

func NewHTTPProxy(config HTTPProxyConfig) (*HTTPProxy, error) {
  h := &HTTPProxy{
    Config: config,
  }

  mux := http.NewServeMux()
  mux.Handle("/", h)
  h.Server.Handler = mux

  return h, nil
}

func (h *HTTPProxy) Start() error {
  var err error

  h.listener, err = net.Listen("tcp", h.Config.Addr)
  if err != nil {
    return err
  }

  return h.Server.Serve(h.listener)
}

func (h *HTTPProxy) Stop() error {
  return h.listener.Close()
}

func (h *HTTPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  hostname := r.Host

  if sep := strings.Index(hostname, ":"); sep >= 0 {
    hostname = hostname[:sep]
  }

  // tag before starting redis queries
  if h.Config.XRequestStart {
    r.Header.Set("X-Request-Start", requestStart())
  }

  if h.Config.XForwardedProto != "" {
    r.Header.Set("X-Forwarded-Proto", h.Config.XForwardedProto)
  }

  if h.Config.XForwardedFor {
    r.Header.Set("X-Forwarded-For", clientIP(r))
  }
{'fraction_non_alphanumeric': 0.12348993288590604, 'fraction_numerical': 0.0006711409395973154, 'mean_word_length': 2.8316195372750643, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3443876', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1026, 'n_words': 238}