package org.wikiwebserver.handler.http.example;

import java.io.IOException;
import java.util.Random;

import org.wikiwebserver.handler.http.HTTPHandler;
import org.wikiwebserver.handler.http.interfaces.CacheableHTTPResponse;
import org.wikiwebserver.handler.http.interfaces.HTTPResponder;

public class ExampleCacheableHTTPResponse implements HTTPResponder, CacheableHTTPResponse {
    
    private Random random = new Random();
    
    public void init(HTTPHandler conn) throws IOException {
        conn.getResponse().getHeaders().set("Content-Type", "application/octet-stream");
    }
    
    public Object respond(HTTPHandler conn) throws IOException {
        byte[] randomData = new byte[100 * 1024];
        random.nextBytes(randomData);
        return randomData;
    }
    
    public String getCacheKey() {
        return "";
    }
    
    public long getExpireTime() {
        return System.currentTimeMillis() + 24 * 60 * 60 * 1000;
    }
}

