<commit_before>// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// 	https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package safehttp

import (
	"net/http"
)

// ResponseWriter TODO
type ResponseWriter struct {
	d  Dispatcher
	rw http.ResponseWriter

	// Having this field unexported is essential for
	// security. Otherwise one can easily overwrite
	// the struct bypassing all our safety guarantees.
	header       Header
	muxInterceps map[string]Interceptor
}

// NewResponseWriter creates a ResponseWriter from a safehttp.Dispatcher, an
// http.ResponseWriter and a list of interceptors associated with a ServeMux.
func NewResponseWriter(d Dispatcher, rw http.ResponseWriter, muxInterceps map[string]Interceptor) ResponseWriter {
	header := newHeader(rw.Header())
	return ResponseWriter{
		d:            d,
		rw:           rw,
		header:       header,
		muxInterceps: muxInterceps,
	}
}

// Interceptor returns the plugin associated with the given key.
func (w *ResponseWriter) Interceptor(key string) Interceptor {
	mp, ok := w.muxInterceps[key]
	if !ok {
		return nil
	}
	return mp
}

// Result TODO
type Result struct {
	written bool
}

// Write TODO
func (w *ResponseWriter) Write(resp Response) Result {
	if err := w.d.Write(w.rw, resp); err != nil {
		panic("error")
	}
	return Result{written: true}
}

// WriteTemplate TODO<commit_msg>fix nit in ResponseWriter godoc<commit_after>// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// 	https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package safehttp

import (
	"net/http"
)

// ResponseWriter TODO
type ResponseWriter struct {
	d  Dispatcher
	rw http.ResponseWriter

	// Having this field unexported is essential for
	// security. Otherwise one can easily overwrite
	// the struct bypassing all our safety guarantees.
	header       Header
	muxInterceps map[string]Interceptor
}

// NewResponseWriter creates a ResponseWriter from a safehttp.Dispatcher, an
// http.ResponseWriter and a list of interceptors associated with a ServeMux.
func NewResponseWriter(d Dispatcher, rw http.ResponseWriter, muxInterceps map[string]Interceptor) ResponseWriter {
	header := newHeader(rw.Header())
	return ResponseWriter{
		d:            d,
		rw:           rw,
		header:       header,
		muxInterceps: muxInterceps,
	}
}

// Interceptor returns the interceptor associated with the given key.
func (w *ResponseWriter) Interceptor(key string) Interceptor {
	mp, ok := w.muxInterceps[key]
	if !ok {
		return nil
	}
	return mp
}

// Result TODO
type Result struct {
	written bool
}

// Write TODO
func (w *ResponseWriter) Write(resp Response) Result {
	if err := w.d.Write(w.rw, resp); err != nil {
		panic("error")
	}
	return Result{written: true}
}

// WriteTemplate TODO
{'fraction_non_alphanumeric': 0.08752378363685784, 'fraction_numerical': 0.004349007882576787, 'mean_word_length': 3.5942571785268416, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '489533', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1033, 'n_words': 421}