<commit_before>package core.framework.api.web;

import core.framework.api.http.ContentType;
import core.framework.api.http.HTTPStatus;
import core.framework.api.util.Maps;
import core.framework.impl.web.response.Body;
import io.undertow.util.Headers;
import io.undertow.util.HttpString;

import java.util.Map;
import java.util.Optional;

/**
 * @author neo
 */
public final class ResponseImpl implements Response {
    public final Map<HttpString, String> headers = Maps.newHashMap();
    public final Body body;
    public Map<CookieSpec, String> cookies;
    private HTTPStatus status = HTTPStatus.OK;
    private ContentType contentType;

    ResponseImpl(Body body) {
        this.body = body;
    }

    @Override
    public HTTPStatus status() {
        return status;
    }

    @Override
    public Response status(HTTPStatus status) {
        this.status = status;
        return this;
    }

    @Override
    public Response header(String name, Object value) {
        headers.put(new HttpString(name), String.valueOf(value));
        return this;
    }

    @Override
    public Optional<ContentType> contentType() {
        return Optional.ofNullable(contentType);
    }

    @Override
    public Response cookie(CookieSpec spec, String value) {
        if (cookies == null) cookies = Maps.newHashMap();
        cookies.put(spec, value);
        return this;
    }

    @Override
    public Response contentType(ContentType contentType) {
        if (contentType != null) {
            this.contentType = contentType;
            headers.put(Headers.CONTENT_TYPE, contentType.toString());
        }
        return this;
    }
}<commit_msg>* site: enable security headers, X-Frame-Options, X-XSS-Protection, X-Content-Type-Options<commit_after>package core.framework.api.web;

import core.framework.api.http.ContentType;
import core.framework.api.http.HTTPStatus;
import core.framework.api.util.Maps;
import core.framework.impl.web.response.Body;
import io.undertow.util.Headers;
import io.undertow.util.HttpString;

import java.util.Map;
import java.util.Optional;

/**
 * @author neo
 */
public final class ResponseImpl implements Response {
    public final Map<HttpString, String> headers = Maps.newHashMap();
    public final Body body;
    public Map<CookieSpec, String> cookies;
    private HTTPStatus status = HTTPStatus.OK;
    private ContentType contentType;

    ResponseImpl(Body body) {
        this.body = body;
    }

    @Override
    public HTTPStatus status() {
        return status;
    }

    @Override
    public Response status(HTTPStatus status) {
        this.status = status;
        return this;
    }

    @Override
    public Response header(String name, Object value) {
        headers.put(new HttpString(name), String.valueOf(value));
        return this;
    }

    @Override
    public Optional<ContentType> contentType() {
        return Optional.ofNullable(contentType);
    }

    @Override
    public Response contentType(ContentType contentType) {
        if (contentType != null) {
            this.contentType = contentType;
            headers.put(Headers.CONTENT_TYPE, contentType.toString());
        }
        return this;
    }

    @Override
    public Response cookie(CookieSpec spec, String value) {
        if (cookies == null) cookies = Maps.newHashMap();
        cookies.put(spec, value);
        return this;
    }
}
{'fraction_non_alphanumeric': 0.09997042295178941, 'fraction_numerical': 0.0, 'mean_word_length': 2.8918296892980435, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6815050', 'n_tokens_mistral': 954, 'n_tokens_neox': 934, 'n_words': 235}