定义了MIN-HTTP基本的包格式

This commit is contained in:
free will committed 2020-11-11 22:12:13 +08:00
1 parent 36f16c6cee
commit 1bca15717d
4 files changed
+156 -10

No files matched your search

@@ -0,0 +1,63 @@
package cn.minbrowser.MiniMinData.util;
import org.json.JSONObject;
/*
* @author wefree
*/
/**
* JSON格式字符串支持类
*/
public class JSONStringFormatUtil {
/**
* 往某个JSONObject中放入一个键值对/String
* @param jsonObject
* @param key
* @param value
* @return
*/
public static JSONObject pushStringValueIntoJSONObject(JSONObject jsonObject, String key, String value) {
try {
jsonObject.put(key, value);
} catch (Exception e) {
// TODO: handle exception
System.out.println("Json exception (pushStringValueIntoJSONObject): " + e.getMessage());
}
return jsonObject;
}
/**
* 往某个JSONObject中放入一个键值对/Integer
* @param jsonObject
* @param key
* @param value
* @return
*/
public static JSONObject pushIntegerValueIntoJSONObject(JSONObject jsonObject,String key,Integer value) {
try {
jsonObject.put(key, value);
} catch (Exception e) {
// TODO: handle exception
System.out.println("Json exception (pushIntegerValueIntoJSONObject): " + e.getMessage());
}
return jsonObject;
}
/**
* 往某个JSONObject中放入一个键值对/Long
* @param jsonObject
* @param key
* @param value
* @return
*/
public static JSONObject pushLongValueIntoJSONObject(JSONObject jsonObject,String key,Long value) {
try {
jsonObject.put(key, value);
} catch (Exception e) {
// TODO: handle exception
System.out.println("Json exception (pushLongValueIntoJSONObject): " + e.getMessage());
}
return jsonObject;
}
}
@@ -0,0 +1,68 @@
package cn.minbrowser.MiniMinData.util;
/*
* @author wefree
*/
import org.json.JSONObject;
/**
* 支持HTTP请求包包头(兴趣包携带的数据)的格式化
*/
public class MINHTTP_DataPacketFormatUtil {
/**
* MIN-HTTP的两种方法
*/
public enum MIN_HTTP_Method{
GET,
POST;
}
/**
* MIN-HTTP版本号
*/
public static String MIN_HTTP_Version_V1="MIN-HTTP/1.0";
// MIN-HTTP请求包头部字段
public static String MIN_HTTP_ContentLength="Content-Length";
public static String MIN_HTTP_ContentType="Content-Type";
public static String MIN_HTTP_IfModifiedSince="If-Modified-Since"; // 预留字段,尚无用到
/**
* 构造一个GET请求包
* @param url
* @param version
* @param ifModifiedSince
* @return
*/
public static String newMINHTTPRequestPacket_GET(String url,String version,String ifModifiedSince){
return MIN_HTTP_Method.GET+" "+url+" "+version+"\n"
+MIN_HTTP_IfModifiedSince+":"+ifModifiedSince;
}
public static String newMINHTTPRequestPacket_GET(String url){
return newMINHTTPRequestPacket_GET(url,MIN_HTTP_Version_V1,"null");
}
/**
* 构造一个POST请求包
* @param url
* @param version
* @param contentLength
* @param contentType
* @param jsonInfo
* @return
*/
public static String newMINHTTPRequestPacket_POST(String url,String version,
Integer contentLength,String contentType,
JSONObject jsonInfo){
return MIN_HTTP_Method.POST+" "+url+" "+version+"\n"
+MIN_HTTP_ContentLength+":"+contentLength+"\n"
+MIN_HTTP_ContentType+":"+contentType+"\n"
+"\n"
+jsonInfo.toString();
}
public static String newMINHTTPRequestPacket_POST(String url,
Integer contentLength,String contentType,
JSONObject jsonInfo){
return newMINHTTPRequestPacket_POST(url,MIN_HTTP_Version_V1,contentLength,contentType,jsonInfo);
}
}
@@ -0,0 +1,16 @@
package cn.minbrowser.MiniMinData.util;
/*
* @author wefree
*/
/**
* 支持HTTP(兴趣包的名称)
*/
public class MINHTTP_MINPrefixUtil {
// 探测包后缀
private static String DetectString="/MIN_SERVICE_DETECT";
// 连接建立包后缀
private static String SessionString="/MIN_HTTP_SESSION";
}
@@ -1,18 +1,17 @@
package cn.minbrowser.protocol.Test;
import cn.minbrowser.protocol.util.PrefixTypeUtil;
public class TestMain {
public static void main(String[] args) {
PrefixTypeUtil.PrefixType testType=PrefixTypeUtil.recognizePrefixType("/MIN/Nginx/test.jpg");
System.out.println(testType);
if(testType.equals(PrefixTypeUtil.PrefixType.HTML)){
System.out.println("done HTML");
}
if(testType.equals(PrefixTypeUtil.PrefixType.CSS)){
System.out.println("done CSS");
}
// PrefixTypeUtil.PrefixType testType=PrefixTypeUtil.recognizePrefixType("/MIN/Nginx/test.jpg");
// System.out.println(testType);
// if(testType.equals(PrefixTypeUtil.PrefixType.HTML)){
// System.out.println("done HTML");
// }
// if(testType.equals(PrefixTypeUtil.PrefixType.CSS)){
// System.out.println("done CSS");
// }
// System.out.println(DataPacketFormatUtil.MIN_HTTP_Version.MIN_HTTP_V1);
}
}