<commit_before>package net

import (
  "fmt"
  "net/http"

  "github.com/gorilla/websocket"

  "kekocity/data/helpers"
  netmsg "kekocity/net/message"
)

func wsHandler(w http.ResponseWriter, r *http.Request) {
  //Handshake
  ws, err := websocket.Upgrade(w, r, nil, 1024, 1024)
  if _, ok := err.(websocket.HandshakeError); ok {
    http.Error(w, "Not a websocket handshake", 400)<commit_msg>Check request origin<commit_after>package net

import (
  "fmt"
  "net/http"

  "github.com/gorilla/websocket"

  "kekocity/data/helpers"
  netmsg "kekocity/net/message"
)

var origins = map[string]bool {
  "http://localhost": true, // development
}

func wsHandler(w http.ResponseWriter, r *http.Request) {
  if !origins[r.Header.Get("Origin")] {
		http.Error(w, "Origin not allowed", 403)
		return
	}
  //Handshake
  ws, err := websocket.Upgrade(w, r, nil, 1024, 1024)
  if _, ok := err.(websocket.HandshakeError); ok {
    http.Error(w, "Not a websocket handshake", 400)
{'fraction_non_alphanumeric': 0.15320910973084886, 'fraction_numerical': 0.025879917184265012, 'mean_word_length': 3.933673469387755, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, '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': '4481981', 'n_tokens_mistral': 395, 'n_tokens_neox': 356, 'n_words': 79}