All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.cosycode.ext.web.http.HttpHeaderHelper Maven / Gradle / Ivy

Go to download

扩展模块, 用于存放一些非常用的工具或模块的扩展类, 例如在poi基础上扩展的excel的导入模块, 模拟按键模块

The newest version!
package com.github.cosycode.ext.web.http;

import lombok.Getter;
import lombok.NonNull;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpHeaders;

import java.util.HashMap;
import java.util.Map;

/**
 * Description : 
 * 

* created in 2023/1/16 *

* * @author CPF * @since 1.0 **/ public class HttpHeaderHelper { public static void jsonHeader(@NonNull Map header) { header.computeIfAbsent(HttpHeaders.CONTENT_TYPE, k -> ContentType.APPLICATION_JSON); header.putIfAbsent(HttpHeaders.ACCEPT_ENCODING, "gzip, x-gzip, deflate"); header.putIfAbsent(HttpHeaders.CONNECTION, "keep-alive"); } public static Map jsonHeader() { Map header = new HashMap<>(); jsonHeader(header); return header; } public static HttpHeaderBuilder build() { return new HttpHeaderBuilder(); } @Getter public static class HttpHeaderBuilder { final Map headers = new HashMap<>(); public Accept accept() { return new Accept(); } public ContentType contentType() { return new ContentType(); } public CacheControl cacheControl() { return new CacheControl(); } public class Accept { public HttpHeaderBuilder application$Json() { HttpHeaderBuilder.this.headers.put("accept", "application/json"); return HttpHeaderBuilder.this; } } public class ContentType { public HttpHeaderBuilder application$Json() { HttpHeaderBuilder.this.headers.put("content-type", "application/json"); return HttpHeaderBuilder.this; } } public class CacheControl { public HttpHeaderBuilder no$cache() { HttpHeaderBuilder.this.headers.put("cache-control", "no-cache"); return HttpHeaderBuilder.this; } } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy