當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServerRequest.getHeader方法代碼示例

本文整理匯總了Java中io.vertx.core.http.HttpServerRequest.getHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServerRequest.getHeader方法的具體用法?Java HttpServerRequest.getHeader怎麽用?Java HttpServerRequest.getHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.vertx.core.http.HttpServerRequest的用法示例。


在下文中一共展示了HttpServerRequest.getHeader方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: refuseNonLanAccess

import io.vertx.core.http.HttpServerRequest; //導入方法依賴的package包/類
/**
 * 判斷當前請求是否允許,如果不允許,則將狀態碼設為403並結束響應
 * 
 * @return true:禁止訪問 false=允許訪問
 * @author Leibniz.Hu
 */
protected boolean refuseNonLanAccess(RoutingContext rc) {
    HttpServerRequest req = rc.request();
    HttpServerResponse resp = rc.response();
    String realIp = req.getHeader("X-Real-IP");
    String xforward = req.getHeader("X-Forwarded-For");
    //禁止外網訪問
    if (realIp != null && !isLanIP(realIp)) {
        log.warn("檢測到非法訪問,來自X-Real-IP={}", realIp);
        resp.setStatusCode(403).end();
        return true;
    }
    if (xforward != null && !isLanIP(xforward)) {
        log.warn("檢測到非法訪問,來自X-Forwarded-For={}", xforward);
        resp.setStatusCode(403).end();
        return true;
    }
    return false;
}
 
開發者ID:Leibnizhu,項目名稱:AlipayWechatPlatform,代碼行數:25,代碼來源:LanAccessSubRouter.java

示例2: authUser

import io.vertx.core.http.HttpServerRequest; //導入方法依賴的package包/類
public static String authUser(HttpServerRequest request, HttpServerResponse response, Config config) {
    String token = request.getHeader("token");
    if (token == null) {
        response.setStatusCode(403);
        response.end();
        return null;
    }

    String userId = ServerUtils.getIdFromToken(config, token);

    if (userId == null) {
        response.setStatusCode(403);
        response.end();
        return null;
    }

    return userId;
}
 
開發者ID:Samoxive,項目名稱:SafetyJim,代碼行數:19,代碼來源:ServerUtils.java

示例3: provide

import io.vertx.core.http.HttpServerRequest; //導入方法依賴的package包/類
@Override
public User provide(HttpServerRequest request) {
	String token = request.getHeader("X-Token");

	// set user ...
	if (token != null) {
		return users.getUser(token);
	}

	return null;
}
 
開發者ID:zandero,項目名稱:rest.vertx,代碼行數:12,代碼來源:UserHandler.java

示例4: provide

import io.vertx.core.http.HttpServerRequest; //導入方法依賴的package包/類
@Override
public Token provide(HttpServerRequest request) {
	String token = request.getHeader("X-Token");
	if (token != null) {
		return new Token(token);
	}

	return null;
}
 
開發者ID:zandero,項目名稱:rest.vertx,代碼行數:10,代碼來源:TokenProvider.java

示例5: getAccessToken

import io.vertx.core.http.HttpServerRequest; //導入方法依賴的package包/類
/**
 * Obtains the access token from the request. It is expected to be the
 * Authorization with a bearer tag. The authentication code is expected to be a
 * given pattern.
 *
 * @param contextRequest
 *            request
 * @return access token
 */
private String getAccessToken(final HttpServerRequest contextRequest) {

    final String authorizationHeader = contextRequest.getHeader(AUTHORIZATION);
    if (authorizationHeader == null) {
        return null;
    }
    final Matcher m = Pattern.compile(BEARER_TOKEN_PATTERN).matcher(authorizationHeader);
    if (!m.matches()) {
        return null;
    } else {
        return m.group(1);
    }
}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:23,代碼來源:ProtectedHandler.java

示例6: handle

import io.vertx.core.http.HttpServerRequest; //導入方法依賴的package包/類
@Override
public void handle(final RoutingContext context) {

    final HttpServerRequest contextRequest = context.request();
    final HttpServerResponse contextResponse = context.response();

    final String requestID = requestIDProvider.newRequestID(context);

    final String token = contextRequest.getFormAttribute("token");
    if (token == null || !TOKEN_PATTERN.matcher(token).matches()) {
        contextResponse
            .setChunked(false)
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .setStatusCode(400)
            .setStatusMessage(BAD_REQUEST)
            .end(Errors.invalidRequest("Missing or invalid token " + token).toBuffer());
        return;
    }

    final String authorization = contextRequest.getHeader(HttpHeaders.AUTHORIZATION);
    if (authorization == null) {
        contextResponse
            .setChunked(false)
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .setStatusCode(401)
            .setStatusMessage("Unauthorized Client")
            .putHeader("WWW-Authenticate", "Basic")
            .end(Errors.unauthorizedClient("Missing authorization").toBuffer());
        return;
    }

    // Trust the authorization endpoint and use the body handler
    final HttpClientRequest revocationRequest = httpClient.post(Conversions.toRequestOptions(authorizationEndpoint.resolve("/revoke")),
        authorizationResponse -> authorizationResponse.bodyHandler(contextResponse
            .setChunked(false)
            .setStatusCode(authorizationResponse.statusCode())
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .putHeader(RequestIDProvider.REQUEST_ID, requestID)
            .setStatusMessage(authorizationResponse.statusMessage())::end));
    revocationRequest
        .putHeader(HttpHeaders.AUTHORIZATION, authorization)
        .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_FORM_URLENCODED)
        .putHeader(HttpHeaders.ACCEPT, MediaTypes.APPLICATION_JSON)
        .putHeader(REQUEST_ID, requestID)
        .putHeader(DATE, RFC_1123_DATE_TIME.format(now(UTC)))
        .end("token_type_hint=refresh_token&token=" + token);

}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:49,代碼來源:RevocationHandler.java

示例7: handle

import io.vertx.core.http.HttpServerRequest; //導入方法依賴的package包/類
@Override
public void handle(final RoutingContext context) {

    final HttpServerRequest contextRequest = context.request();
    final HttpServerResponse contextResponse = context.response();

    final String requestID = requestIDProvider.newRequestID(context);

    final String grantType = contextRequest.getFormAttribute("grant_type");
    if (grantType == null) {
        contextResponse
            .setChunked(false)
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .setStatusCode(400)
            .setStatusMessage(BAD_REQUEST)
            .end(Errors.invalidGrant("Missing grant type").toBuffer());
        return;
    }

    final String authorization = contextRequest.getHeader(HttpHeaders.AUTHORIZATION);
    if (authorization == null) {
        contextResponse
            .setChunked(false)
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .setStatusCode(401)
            .setStatusMessage("Unauthorized Client")
            .putHeader("WWW-Authenticate", "Basic")
            .end(Errors.unauthorizedClient("Missing authorization").toBuffer());
        return;
    }

    if (!"refresh_token".equals(grantType)) {
        contextResponse
            .setChunked(false)
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .setStatusCode(400)
            .setStatusMessage(BAD_REQUEST)
            .end(Errors.build("unsupported_grant_type", "Unsupported grant type").toBuffer());
        return;
    }
    final String refreshToken = contextRequest.getFormAttribute("refresh_token");
    if (refreshToken == null || !TOKEN_PATTERN.matcher(refreshToken).matches()) {
        contextResponse
            .setChunked(false)
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .setStatusCode(400)
            .setStatusMessage(BAD_REQUEST)
            .end(Errors.invalidGrant("Invalid grant").toBuffer());
        return;
    }

    // Trust the authorization endpoint and use the body handler
    final HttpClientRequest authorizationRequest = httpClient.post(Conversions.toRequestOptions(authorizationEndpoint.resolve("/token")),
        authorizationResponse -> authorizationResponse.bodyHandler(contextResponse
            .setChunked(false)
            .setStatusCode(authorizationResponse.statusCode())
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .putHeader(RequestIDProvider.REQUEST_ID, requestID)
            .setStatusMessage(authorizationResponse.statusMessage())::end));
    authorizationRequest
        .putHeader(HttpHeaders.AUTHORIZATION, authorization)
        .putHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded")
        .putHeader(HttpHeaders.ACCEPT, "application/json")
        .putHeader(REQUEST_ID, requestID)
        .putHeader(DATE, RFC_1123_DATE_TIME.format(now(UTC)))
        .end("grant_type=refresh_token&refresh_token=" + refreshToken);

}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:69,代碼來源:RefreshHandler.java


注:本文中的io.vertx.core.http.HttpServerRequest.getHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。