<commit_before>import { Injectable } from '@angular/core';
import { Http, Headers, URLSearchParams } from '@angular/http';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class HttpAuthenticationService {
    private token: string = "";
    
    constructor(private http: Http){}
    
    public get(url: string, options:any = {} ){
        options.headers = options.headers ? options.headers : new Headers();
        this.getAuthenticationHeader(options.headers);
        this.getContentTypeHeader(options.headers);
        return this.http.get(url, options);
    }
    
    public put(url: string, body: string, options: any = {}){
        options.headers = options.headers ? options.headers : new Headers(); 
        this.getAuthenticationHeader(options.headers);
        return this.http.put(url, body, options);
    }
    
    public delete(url: string, options: any = {}){
        options.headers = options.headers ? options.headers : new Headers();
        this.getAuthenticationHeader(options.headers);
        return this.http.delete(url, options);
    }
    
    private getAuthenticationHeader(headers: Headers){
        headers.append('Authorization', 'Baerer ' + this.getToken());
    }
    
    private getContentTypeHeader(headers: Headers){
        headers.append('Content-Type', 'application/json');
    }
    
    private getToken(): string{
        // TODO check token
        return this.token;
    }
    
    public authenticate(url: string, username:string, password: string): Observable<any>{
        return Observable.create(observer => {

            let headers = new Headers({
                'Content-Type': 'application/x-www-form-urlencoded'
            });
            let params = {
                username: username,
                password: password
            };
            
            this.http.post(url, this.urlEncode(params), { headers: headers }).
            subscribe(token => {
                this.token = token['_body'];
                observer.next("ready");
                observer.complete;
            });
        });   
    }
    
    private urlEncode(obj: Object): string{
        let urlSearchParams = new URLSearchParams();
        for(let key in obj){
            urlSearchParams.append(key, obj[key]);
        }
        return urlSearchParams.toString();
    }<commit_msg>Content-Type Header replaced with Accept Header<commit_after>import { Injectable } from '@angular/core';
import { Http, Headers, URLSearchParams } from '@angular/http';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class HttpAuthenticationService {
    private token: string = "";
    
    constructor(private http: Http){}
    
    public get(url: string, options:any = {} ){
        options.headers = options.headers ? options.headers : new Headers();
        this.getAuthenticationHeader(options.headers);
        this.getAcceptHeader(options.headers);
        return this.http.get(url, options);
    }
    
    public put(url: string, body: string, options: any = {}){
        options.headers = options.headers ? options.headers : new Headers(); 
        this.getAuthenticationHeader(options.headers);
        return this.http.put(url, body, options);
    }
    
    public delete(url: string, options: any = {}){
        options.headers = options.headers ? options.headers : new Headers();
        this.getAuthenticationHeader(options.headers);
        return this.http.delete(url, options);
    }
    
    private getAuthenticationHeader(headers: Headers){
        headers.append('Authorization', 'Baerer ' + this.getToken());
    }
    
    private getAcceptHeader(headers: Headers){
        headers.append('Accept', 'application/json');
    }
    
    private getToken(): string{
        // TODO check token
        return this.token;
    }
    
    public authenticate(url: string, username:string, password: string): Observable<any>{
        return Observable.create(observer => {

            let headers = new Headers({
                'Content-Type': 'application/x-www-form-urlencoded'
            });
            this.getAcceptHeader(headers);
            let params = {
                username: username,
                password: password
            };
            
            this.http.post(url, this.urlEncode(params), { headers: headers }).
            subscribe(token => {
                this.token = token['_body'];
                observer.next("ready");
                observer.complete;
            });
        });   
    }
    
    private urlEncode(obj: Object): string{
        let urlSearchParams = new URLSearchParams();
        for(let key in obj){
            urlSearchParams.append(key, obj[key]);
        }
        return urlSearchParams.toString();
    }
{'fraction_non_alphanumeric': 0.11947180884510585, 'fraction_numerical': 0.0, 'mean_word_length': 2.259562841530055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '2404366', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1220, 'n_words': 274}