forked from EliMirren/VX-API-Gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mirren
authored and
Mirren
committed
May 6, 2018
1 parent
f713d20
commit 200e554
Showing
2 changed files
with
214 additions
and
33 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/main/java/com/szmirren/vxApi/core/common/HttpUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.szmirren.vxApi.core.common; | ||
|
||
import java.nio.charset.Charset; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import io.netty.handler.codec.http.QueryStringDecoder; | ||
import io.vertx.core.MultiMap; | ||
import io.vertx.core.http.CaseInsensitiveHeaders; | ||
|
||
/** | ||
* HTTP相关的工具 | ||
* | ||
* @author <a href="http://szmirren.com">Mirren</a> | ||
* | ||
*/ | ||
public class HttpUtils { | ||
/** | ||
* 解码URI中的参数,既?后面的参数 | ||
* | ||
* @param uri | ||
* uri参数,默认以utf-8方式 | ||
* @return 返回解码后的结果或者返回新的MultiMap | ||
*/ | ||
public static MultiMap decoderUriParams(String uri) { | ||
return decoderUriParams(uri, Charset.forName("UTF-8")); | ||
} | ||
|
||
/** | ||
* 解码URI中的参数,既?后面的参数 | ||
* | ||
* @param uri | ||
* uri参数 | ||
* @param charset | ||
* 解码格式,如果该字段为空则默认为utf-8方式 | ||
* @return 返回解码后的结果或者返回新的MultiMap,如果发生异常返回新的MultiMap | ||
*/ | ||
public static MultiMap decoderUriParams(String uri, Charset charset) { | ||
try { | ||
if (charset == null) { | ||
charset = Charset.forName("UTF-8"); | ||
} | ||
QueryStringDecoder decode = new QueryStringDecoder(uri, charset, false); | ||
Map<String, List<String>> paramMap = decode.parameters(); | ||
MultiMap params = new CaseInsensitiveHeaders(); | ||
if (!paramMap.isEmpty()) { | ||
for (Map.Entry<String, List<String>> entry : paramMap.entrySet()) { | ||
params.add(entry.getKey(), entry.getValue()); | ||
} | ||
} | ||
return params; | ||
} catch (Exception e) { | ||
return new CaseInsensitiveHeaders(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters