<commit_before>package latis.writer

import latis.dm.Dataset
import javax.servlet.http.HttpServletResponse

/**
 * Decorate a Writer to write via a ServletResponse.
 */
class HttpServletWriter(writer: Writer, response: HttpServletResponse) extends Writer {
  //TODO: consider writers that can't stream, write tmp file
  //  or simply serve an existing file!?

  
  def write(dataset: Dataset, args: Seq[String]): Unit = {
  //def write(dataset: Dataset) {
    //write http header stuff
            
    //Set the Content-Type HTTP header
    response.setContentType(writer.getMimeType());
        
//TODO: add other headers
//        //Set the Content-Description HTTP header
//        String cd = writer.getContentDescription(); 
//        if (cd == null) cd = "tss-" + type;
//        response.setHeader("Content-Description", cd);
//        
//        //Set date headers
//        long date = System.currentTimeMillis();
//        response.addDateHeader("Date", date);
//        response.addDateHeader("Last-Modified", date);
//        //TODO: use data publish date for Last-Modified? 
//        
//        //Set other HTTP headers
//        String dodsServer = TSSProperties.getProperty("server.dods");
//        response.setHeader("XDODS-Server", dodsServer); 
//        String server = TSSProperties.getProperty("server.tss");
//        response.setHeader("Server", server); 
        <commit_msg>Use CORS to allow cross-origin requests<commit_after>package latis.writer

import latis.dm.Dataset
import javax.servlet.http.HttpServletResponse
import latis.util.LatisProperties

/**
 * Decorate a Writer to write via a ServletResponse.
 */
class HttpServletWriter(writer: Writer, response: HttpServletResponse) extends Writer {
  //TODO: consider writers that can't stream, write tmp file
  //  or simply serve an existing file!?

  
  def write(dataset: Dataset, args: Seq[String]): Unit = {
  //def write(dataset: Dataset) {
    //write http header stuff
            
    //Set the Content-Type HTTP header
    response.setContentType(writer.getMimeType());
    
    //Define the allowed origin for cross-origin resource sharing (CORS)
    //TODO: get from properties, compare with Origin in request header
    //Just allow everything for now.
//    LatisProperties.get("allow.origin") match {
//      case Some(s) => response.addHeader("Access-Control-Allow-Origin", s)
//      case None => 
//    }
    response.addHeader("Access-Control-Allow-Origin", "*")
        
//TODO: add other headers
//        //Set the Content-Description HTTP header
//        String cd = writer.getContentDescription(); 
//        if (cd == null) cd = "tss-" + type;
//        response.setHeader("Content-Description", cd);
//        
//        //Set date headers
//        long date = System.currentTimeMillis();
//        response.addDateHeader("Date", date);
//        response.addDateHeader("Last-Modified", date);
//        //TODO: use data publish date for Last-Modified? 
//        
//        //Set other HTTP headers
//        String dodsServer = TSSProperties.getProperty("server.dods");
//        response.setHeader("XDODS-Server", dodsServer); 
//        String server = TSSProperties.getProperty("server.tss");
//        response.setHeader("Server", server); 
        
{'fraction_non_alphanumeric': 0.12798530312308634, 'fraction_numerical': 0.0, 'mean_word_length': 2.601984564498346, 'pattern_counts': {'":': 0, '<': 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': '2762478', 'n_tokens_mistral': 905, 'n_tokens_neox': 899, 'n_words': 252}