<commit_before>package com.microsoft.graph.httpcore;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;

public class RedirectHandler extends DefaultRedirectStrategy{
	
	public static final RedirectHandler INSTANCE = new RedirectHandler();
	
    @Override
    public boolean isRedirected(
            final HttpRequest request,
            final HttpResponse response,
            final HttpContext context) throws ProtocolException {
        Args.notNull(request, "HTTP request");
        Args.notNull(response, "HTTP response");

        final int statusCode = response.getStatusLine().getStatusCode();
        final Header locationHeader = response.getFirstHeader("location");
        if(locationHeader == null)
        	return false;
        
        if(statusCode == HttpStatus.SC_MOVED_TEMPORARILY ||
        		statusCode == HttpStatus.SC_MOVED_PERMANENTLY ||
        		statusCode == HttpStatus.SC_TEMPORARY_REDIRECT ||
        		statusCode == HttpStatus.SC_SEE_OTHER)
        	return true;
        
        return false;
    }
    
    @Override
    public HttpUriRequest getRedirect(
    		final HttpRequest request,
    		final HttpResponse response,
    		final HttpContext context) throws ProtocolException {
    	final URI uri = getLocationURI(request, response, context);
    	try {
    		final URI requestURI = new URI(request.getRequestLine().getUri());
    		if(!uri.getHost().equalsIgnoreCase(requestURI.getHost()) || 
    				!uri.getScheme().equalsIgnoreCase(requestURI.getScheme()))
    			request.removeHeaders("Authorization");	
    	}
    	catch (final URISyntaxException ex) {
    		throw new ProtocolException(ex.getMessage(), ex);
    	}
    	
    	final int status = response.getStatusLine().getStatusCode();
    	if(status == HttpStatus.SC_SEE_OTHER)
    		return new HttpGet(uri);
    	return RequestBuilder.copy(request).setUri(uri).build();
    }
}<commit_msg>Add support to redirect when status code received is 308 in RedirectHandler<commit_after>package com.microsoft.graph.httpcore;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;

public class RedirectHandler extends DefaultRedirectStrategy{
	
	public static final RedirectHandler INSTANCE = new RedirectHandler();
	
    @Override
    public boolean isRedirected(
            final HttpRequest request,
            final HttpResponse response,
            final HttpContext context) throws ProtocolException {
        Args.notNull(request, "HTTP request");
        Args.notNull(response, "HTTP response");

        final int statusCode = response.getStatusLine().getStatusCode();
        final Header locationHeader = response.getFirstHeader("location");
        if(locationHeader == null)
        	return false;
        
        if(statusCode == HttpStatus.SC_MOVED_TEMPORARILY ||
        		statusCode == HttpStatus.SC_MOVED_PERMANENTLY ||
        		statusCode == HttpStatus.SC_TEMPORARY_REDIRECT ||
        		statusCode == HttpStatus.SC_SEE_OTHER ||
        		statusCode == 308)
        	return true;
        
        return false;
    }
    
    @Override
    public HttpUriRequest getRedirect(
    		final HttpRequest request,
    		final HttpResponse response,
    		final HttpContext context) throws ProtocolException {
    	final URI uri = getLocationURI(request, response, context);
    	try {
    		final URI requestURI = new URI(request.getRequestLine().getUri());
    		if(!uri.getHost().equalsIgnoreCase(requestURI.getHost()) || 
    				!uri.getScheme().equalsIgnoreCase(requestURI.getScheme()))
    			request.removeHeaders("Authorization");	
    	}
    	catch (final URISyntaxException ex) {
    		throw new ProtocolException(ex.getMessage(), ex);
    	}
    	
    	final int status = response.getStatusLine().getStatusCode();
    	if(status == HttpStatus.SC_SEE_OTHER)
    		return new HttpGet(uri);
    	return RequestBuilder.copy(request).setUri(uri).build();
    }
}
{'fraction_non_alphanumeric': 0.09560461818918371, 'fraction_numerical': 0.0012153129430828439, 'mean_word_length': 3.4566787003610107, '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': '3955470', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1383, 'n_words': 285}