<commit_before>extern mod extra;
extern mod http;

use std::rt::io::net::ip::{SocketAddr, Ipv4Addr};
use extra::time;

use http::server::{Config, Server, Request, ResponseWriter};
use http::headers::content_type::MediaType;

use application::*;
use application::response::*;

#[deriving(Clone)]
pub struct WidmannServer<T> {
  application: Application<T>
}

impl<T> WidmannServer<T> {
  pub fn new(application: Application<T>) -> WidmannServer<T> {
    WidmannServer { application: application }
  }
}

impl<T: ToResponse> Server for WidmannServer<T> {
    fn get_config(&self) -> Config {
      Config { bind_address: SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 8001 } }
    }

    fn handle_request(&self, r: &Request, w: &mut ResponseWriter) {
      let response = self.application.call(r);

      w.headers.date = Some(time::now_utc());
      w.headers.content_type = Some(MediaType {
          type_: ~"text",
          subtype: ~"plain",
          parameters: ~[(~"charset", ~"UTF-8")]
      });
      w.headers.server = Some(~"Example");

      w.headers.content_length = Some(response.body.len());

      w.status = response.status;
      //w.write(response.body.as_bytes());
    }
}<commit_msg>Buggy version to ilustrate problems<commit_after>extern mod extra;
extern mod http;

use std::rt::io::net::ip::{SocketAddr, Ipv4Addr};
use std::rt::io::Writer;
use extra::time;

use http::server::{Config, Server, Request, ResponseWriter};
use http::headers::content_type::MediaType;

use application::*;
use application::response::*;

#[deriving(Clone)]
pub struct WidmannServer<T> {
  application: Application<T>
}

impl<T> WidmannServer<T> {
  pub fn new(application: Application<T>) -> WidmannServer<T> {
    WidmannServer { application: application }
  }
}

impl<T: ToResponse> Server for WidmannServer<T> {
    fn get_config(&self) -> Config {
      Config { bind_address: SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 8001 } }
    }

    fn handle_request(&self, r: &Request, w: &mut ResponseWriter) {
      let response = self.application.call(r);

      w.headers.date = Some(time::now_utc());
      w.headers.content_type = Some(MediaType {
          type_: ~"text",
          subtype: ~"plain",
          parameters: ~[(~"charset", ~"UTF-8")]
      });
      w.headers.server = Some(~"Example");

      w.headers.content_length = Some(response.body.len());

      w.status = response.status;
      w.write(response.body.as_bytes());
    }
}
{'fraction_non_alphanumeric': 0.16483516483516483, 'fraction_numerical': 0.010582010582010581, 'mean_word_length': 3.8101761252446185, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, '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': '2610323', 'n_tokens_mistral': 846, 'n_tokens_neox': 811, 'n_words': 174}