<commit_before>// Copyright (c) 2013 Conformal Systems LLC.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package main

import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"github.com/conformal/btcchain"
	"github.com/conformal/btcjson"
	"github.com/conformal/btcscript"
	"github.com/conformal/btcwire"
	"github.com/davecgh/go-spew/spew"
	"math/big"
	"net"
	"net/http"
	"strconv"
	"strings"
	"sync"
	"sync/atomic"
)

// rpcServer holds the items the rpc server may need to access (config,
// shutdown, main server, etc.)
type rpcServer struct {
	started   int32
	shutdown  int32
	server    *server
	wg        sync.WaitGroup
	rpcport   string
	username  string
	password  string
	listeners []net.Listener
}

// Start is used by server.go to start the rpc listener.
func (s *rpcServer) Start() {
	if atomic.AddInt32(&s.started, 1) != 1 {
		return
	}

	log.Trace("[RPCS] Starting RPC server")
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		login := s.username + ":" + s.password
		auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login))
		if r.Header["Authorization"][0] == auth {
			jsonRPCRead(w, r, s)
		} else {
			log.Warnf("[RPCS] Auth failure.")
			jsonAuthFail(w, r, s)
		}
	})
	httpServer := &http.Server{}
	for _, listener := range s.listeners {<commit_msg>Handle case where no auth is sent to rpcserver.<commit_after>// Copyright (c) 2013 Conformal Systems LLC.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package main

import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"github.com/conformal/btcchain"
	"github.com/conformal/btcjson"
	"github.com/conformal/btcscript"
	"github.com/conformal/btcwire"
	"github.com/davecgh/go-spew/spew"
	"math/big"
	"net"
	"net/http"
	"strconv"
	"strings"
	"sync"
	"sync/atomic"
)

// rpcServer holds the items the rpc server may need to access (config,
// shutdown, main server, etc.)
type rpcServer struct {
	started   int32
	shutdown  int32
	server    *server
	wg        sync.WaitGroup
	rpcport   string
	username  string
	password  string
	listeners []net.Listener
}

// Start is used by server.go to start the rpc listener.
func (s *rpcServer) Start() {
	if atomic.AddInt32(&s.started, 1) != 1 {
		return
	}

	log.Trace("[RPCS] Starting RPC server")
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		login := s.username + ":" + s.password
		auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login))
		authhdr := r.Header["Authorization"]
		if len(authhdr) > 0 && authhdr[0] == auth {
			jsonRPCRead(w, r, s)
		} else {
			log.Warnf("[RPCS] Auth failure.")
			jsonAuthFail(w, r, s)
		}
	})
	httpServer := &http.Server{}
	for _, listener := range s.listeners {
{'fraction_non_alphanumeric': 0.13798059647862018, 'fraction_numerical': 0.012576356449874237, 'mean_word_length': 3.616915422885572, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 4, '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': '4280714', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1018, 'n_words': 276}