@Override public String rawMethod() { if (rawMethod == null) { rawMethod = request.method().toString(); } return rawMethod; }
@Override public io.vertx.core.http.HttpMethod method() { if (method == null) { String sMethod = request.method().toString(); try { method = io.vertx.core.http.HttpMethod.valueOf(sMethod); } catch (IllegalArgumentException e) { method = io.vertx.core.http.HttpMethod.OTHER; } } return method; }
String remoteIpStr = (remoteIp != null && !remoteIp.isEmpty()) ? remoteIp : "-"; String port = localPort != null ? localPort.toString() : "-"; String method = request != null ? request.method().toString().toUpperCase() : "-"; String uri = request != null ? request.uri() : "-"; String status = response != null ? String.valueOf(response.status().code()) : "-";
protected void captureRequestHeaderSize(HttpRequest httpRequest) { String requestLine = httpRequest.getMethod().toString() + ' ' + httpRequest.getUri() + ' ' + httpRequest.getProtocolVersion().toString(); // +2 => CRLF after status line, +4 => header/data separation long requestHeadersSize = requestLine.length() + 6; HttpHeaders headers = httpRequest.headers(); requestHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers); harEntry.getRequest().setHeadersSize(requestHeadersSize); }
String remoteIpStr = (remoteIp != null && !remoteIp.isEmpty()) ? remoteIp : "-"; String port = localPort != null ? localPort.toString() : "-"; String method = request != null ? request.method().toString().toUpperCase() : "-"; String uri = request != null ? request.uri() : "-"; String status = response != null ? String.valueOf(response.status().code()) : "-";
LOG.error("Got invalid HTTP method: expecting only POST"); throw new BadRequestException( "Incorrect method " + httpRequest.getMethod().toString() + ", expected POST" );
/** * Creates a new {@link HarRequest} object for this failed HTTP CONNECT. Does not populate fields within the request, * such as the error message. * * @param httpConnectRequest the HTTP CONNECT request that failed * @return a new HAR request object */ private HarRequest createRequestForFailedConnect(HttpRequest httpConnectRequest) { String url = getFullUrl(httpConnectRequest); return new HarRequest(httpConnectRequest.getMethod().toString(), url, httpConnectRequest.getProtocolVersion().text()); }
/** * Creates a HarRequest object using the method, url, and HTTP version of the specified request. * * @param httpRequest HTTP request on which the HarRequest will be based * @return a new HarRequest object */ private HarRequest createHarRequestForHttpRequest(HttpRequest httpRequest) { // the HAR spec defines the request.url field as: // url [string] - Absolute URL of the request (fragments are not included). // the URI on the httpRequest may only identify the path of the resource, so find the full URL. // the full URL consists of the scheme + host + port (if non-standard) + path + query params + fragment. String url = getFullUrl(httpRequest); return new HarRequest(httpRequest.getMethod().toString(), url, httpRequest.getProtocolVersion().text()); }
public static HttpRequest newRequest(final FullHttpRequest request) { QueryStringDecoder decoder = new QueryStringDecoder(request.uri()); ImmutableMap<String, String[]> queries = toQueries(decoder); return builder() .withVersion(HttpProtocolVersion.versionOf(request.protocolVersion().text())) .withHeaders(toHeaders(request)) .withMethod(HttpMethod.valueOf(request.method().toString().toUpperCase())) .withUri(decoder.path()) .withQueries(queries) .withContent(toMessageContent(request)) .build(); }
@Override public String rawMethod() { if (rawMethod == null) { rawMethod = request.method().toString(); } return rawMethod; }
public void interpretHttpRequest(HttpRequest nettyHttpRequest) { _httpMethod = nettyHttpRequest.getMethod().toString(); try { URI uri = new URI(nettyHttpRequest.getUri()); if (uri.isAbsolute()) { _uri = uri; } else { String hostName = nettyHttpRequest.headers().get(HttpHeaders.Names.HOST); if (!Strings.isNullOrEmpty(hostName)) { _uri = new URI(String.format("https://%s%s", hostName, uri)); } else { _path = uri.toString(); } } } catch (URISyntaxException e) { throw new IllegalStateException("Invalid URI in underlying request", e); } }
@Override public io.vertx.core.http.HttpMethod method() { if (method == null) { String sMethod = request.method().toString(); try { method = io.vertx.core.http.HttpMethod.valueOf(sMethod); } catch (IllegalArgumentException e) { method = io.vertx.core.http.HttpMethod.OTHER; } } return method; }
@Test public void testTrackResponse() throws Exception { // setup mock returns for query POST String requestUri = "/v2.0/" + tenantId + "/metrics/search"; when(httpRequestMock.getUri()).thenReturn(requestUri); when(httpMethodMock.toString()).thenReturn("GET"); when(httpRequestMock.getMethod()).thenReturn(httpMethodMock); List<String> paramValues = new ArrayList<String>(); paramValues.add("locator1"); queryParams.put("query", paramValues); when((httpRequestMock).getQueryParams()).thenReturn(queryParams); when(httpResponseStatusMock.code()).thenReturn(200); when(httpResponseMock.getStatus()).thenReturn(httpResponseStatusMock); //when(channelBufferMock.toString(any(Charset.class))).thenReturn( String result = "[TRACKER] Response for tenantId " + tenantId; when(httpResponseMock.content()).thenReturn(Unpooled.copiedBuffer(result.getBytes("UTF-8"))); // add tenant and track tracker.addTenant(tenantId); tracker.trackResponse(httpRequestMock, httpResponseMock); // verify verify(loggerMock, atLeastOnce()).info("[TRACKER] tenantId " + tenantId + " added."); verify(loggerMock, times(1)).info("[TRACKER] Response for tenantId " + tenantId + " GET request " + requestUri + "?query=locator1\n" + "RESPONSE_STATUS: 200\n" + "RESPONSE HEADERS: \n" + "RESPONSE_CONTENT:\n" + "[TRACKER] Response for tenantId " + tenantId); }
@Test public void testBuildHttpMethod() { HttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "http://www.google.com"); RecordedHttpRequestBuilder recordedHttpRequestBuilder = new RecordedHttpRequestBuilder(nettyRequest); RecordedHttpRequest recordedHttpRequest = recordedHttpRequestBuilder.build(); Assert.assertEquals(recordedHttpRequest.getMethod(), HttpMethod.GET.toString()); }
when(httpMethodMock.toString()).thenReturn("POST"); when(httpRequestMock.getMethod()).thenReturn(httpMethodMock);
/** * @return the method of the request */ @Override public String getMethod() { return request.getMethod().toString(); }
/** * @return the method of the request */ @Override public String getMethod() { return request.getMethod().toString(); }
protected void captureRequestHeaderSize(HttpRequest httpRequest) { Log.e("InnerHandle", "captureRequestHeaderSize " + harEntry.getId()); String requestLine = httpRequest.getMethod().toString() + ' ' + httpRequest.getUri() + ' ' + httpRequest.getProtocolVersion().toString(); // +2 => CRLF after status line, +4 => header/data separation long requestHeadersSize = requestLine.length() + 6; HttpHeaders headers = httpRequest.headers(); requestHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers); harRequest.getRequest().setHeadersSize(requestHeadersSize); }
/** * Creates a new {@link HarRequest} object for this failed HTTP CONNECT. Does not populate fields within the request, * such as the error message. * * @param httpConnectRequest the HTTP CONNECT request that failed * @return a new HAR request object */ private HarRequest createRequestForFailedConnect(HttpRequest httpConnectRequest) { String url = getFullUrl(httpConnectRequest); return new HarRequest(httpConnectRequest.getMethod().toString(), url, httpConnectRequest.getProtocolVersion().text()); }
/** * Creates a new {@link HarRequest} object for this failed HTTP CONNECT. Does not populate fields within the request, * such as the error message. * * @param httpConnectRequest the HTTP CONNECT request that failed * @return a new HAR request object */ private HarRequest createRequestForFailedConnect(HttpRequest httpConnectRequest) { String url = getFullUrl(httpConnectRequest); return new HarRequest(httpConnectRequest.getMethod().toString(), url, httpConnectRequest.getProtocolVersion().text()); }