<commit_before>package server

import (
	"encoding/json"
	"net/http"

	"appengine"
)

func init() {
	http.HandleFunc("/json/", loadHandler)
}

func loadHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	id, ok := parseIdParam(w, r)
	if !ok {
		return
	}

	m, ok := loadMovie(w, r, id)
	if !ok {
		return
	}

	data, err := json.Marshal(&m)
	if err != nil {
		c.Errorf("can't marshal JSON for movie %v: %v", id, err)
		http.Error(w, "can't encode movie", http.StatusBadRequest)
		return
	}

	w.Header().Add("Content-Type", "text/json") // not correct but "text/" is needed by Dart
	_, err = w.Write(data)
	if err != nil {
		c.Debugf("can't write json to client: %v", err)
	}
}<commit_msg>use correct json mime type<commit_after>package server

import (
	"encoding/json"
	"net/http"

	"appengine"
)

func init() {
	http.HandleFunc("/json/", loadHandler)
}

func loadHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	id, ok := parseIdParam(w, r)
	if !ok {
		return
	}

	m, ok := loadMovie(w, r, id)
	if !ok {
		return
	}

	data, err := json.Marshal(&m)
	if err != nil {
		c.Errorf("can't marshal JSON for movie %v: %v", id, err)
		http.Error(w, "can't encode movie", http.StatusBadRequest)
		return
	}

	w.Header().Add("Content-Type", "application/json")
	_, err = w.Write(data)
	if err != nil {
		c.Debugf("can't write json to client: %v", err)
	}
}
{'fraction_non_alphanumeric': 0.17246273953158267, 'fraction_numerical': 0.0, 'mean_word_length': 3.622950819672131, 'pattern_counts': {'":': 0, '<': 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': '1260207', 'n_tokens_mistral': 584, 'n_tokens_neox': 551, 'n_words': 146}