private HttpMethod httpMethod(WebRequest webRequest) { String httpMethod = webRequest.getHttpMethod().name(); return HttpMethod.valueOf(httpMethod); }
public MockHttpServletRequest buildRequest(ServletContext servletContext) { Charset charset = getCharset(); String httpMethod = this.webRequest.getHttpMethod().name(); UriComponents uriComponents = uriComponents(); String path = uriComponents.getPath(); MockHttpServletRequest request = new HtmlUnitMockHttpServletRequest( servletContext, httpMethod, (path != null ? path : "")); parent(request, this.parentBuilder); String host = uriComponents.getHost(); request.setServerName(host != null ? host : ""); // needs to be first for additional headers authType(request); request.setCharacterEncoding(charset.name()); content(request, charset); contextPath(request, uriComponents); contentType(request); cookies(request); headers(request); locales(request); servletPath(uriComponents, request); params(request, uriComponents); ports(uriComponents, request); request.setProtocol("HTTP/1.1"); request.setQueryString(uriComponents.getQuery()); String scheme = uriComponents.getScheme(); request.setScheme(scheme != null ? scheme : ""); request.setPathInfo(null); return postProcess(request); }
/** * Returns the method that was used in the last call to submitRequest(). * * @return the method that was used in the last call to submitRequest() */ public HttpMethod getLastMethod() { return lastRequest_.getHttpMethod(); }
/** * Returns the method that was used in the last call to submitRequest(). * * @return the method that was used in the last call to submitRequest() */ public HttpMethod getLastMethod() { return lastRequest_.getHttpMethod(); }
@Override public String toString() { return "XMLHttpRequest " + webRequest_.getHttpMethod() + " '" + webRequest_.getUrl() + "'"; } };
@Override public String getHttpMethod() { return request.getHttpMethod().name(); }
@Override public String toString() { return "XMLHttpRequest " + webRequest_.getHttpMethod() + " '" + webRequest_.getUrl() + "'"; } };
@Override public String getHttpMethod() { return request.getHttpMethod().name(); }
private boolean isPreflight() { final HttpMethod method = webRequest_.getHttpMethod(); if (method != HttpMethod.GET && method != HttpMethod.HEAD && method != HttpMethod.POST) { return true; } for (final Entry<String, String> header : webRequest_.getAdditionalHeaders().entrySet()) { if (isPreflightHeader(header.getKey().toLowerCase(Locale.ROOT), header.getValue())) { return true; } } return false; }
private boolean isPreflight() { final HttpMethod method = webRequest_.getHttpMethod(); if (method != HttpMethod.GET && method != HttpMethod.HEAD && method != HttpMethod.POST) { return true; } for (final Entry<String, String> header : webRequest_.getAdditionalHeaders().entrySet()) { if (isPreflightHeader(header.getKey().toLowerCase(Locale.ROOT), header.getValue())) { return true; } } return false; }
private boolean isPreflight() { final HttpMethod method = webRequest_.getHttpMethod(); if (method != HttpMethod.GET && method != HttpMethod.HEAD && method != HttpMethod.POST) { return true; } for (final Entry<String, String> header : webRequest_.getAdditionalHeaders().entrySet()) { if (isPreflightHeader(header.getKey().toLowerCase(Locale.ROOT), header.getValue())) { return true; } } return false; }
private boolean isPreflight() { final HttpMethod method = webRequest_.getHttpMethod(); if (method != HttpMethod.GET && method != HttpMethod.HEAD && method != HttpMethod.POST) { return true; } for (final Entry<String, String> header : webRequest_.getAdditionalHeaders().entrySet()) { if (isPreflightHeader(header.getKey().toLowerCase(Locale.ROOT), header.getValue())) { return true; } } return false; }
/** * Determines if the specified response can be cached. * * @param request the performed request * @param response the received response * @return {@code true} if the response can be cached */ protected boolean isCacheable(final WebRequest request, final WebResponse response) { return HttpMethod.GET == response.getWebRequest().getHttpMethod() && isCacheableContent(response); }
/** * Determines if the specified response can be cached. * * @param request the performed request * @param response the received response * @return {@code true} if the response can be cached */ protected boolean isCacheable(final WebRequest request, final WebResponse response) { return HttpMethod.GET == response.getWebRequest().getHttpMethod() && isCacheableContent(response); }
/** * Creates a faked WebResponse for the request with the provided content. * @param wr the web request for which a response should be created * @param content the content to place in the response * @param contentType the content type of the response * @param responseCode the HTTP code for the response * @param responseMessage the HTTP message for the response * @return a web response with the provided content * @throws IOException if an encoding problem occurred */ protected WebResponse createWebResponse(final WebRequest wr, final String content, final String contentType, final int responseCode, final String responseMessage) throws IOException { final List<NameValuePair> headers = new ArrayList<>(); headers.add(new NameValuePair(HttpHeader.CONTENT_TYPE_LC, contentType + "; charset=" + UTF_8)); final byte[] body = content.getBytes(UTF_8); final WebResponseData wrd = new WebResponseData(body, responseCode, responseMessage, headers); return new WebResponse(wrd, wr.getUrl(), wr.getHttpMethod(), 0); } }
private HistoryEntry(final Page page) { // verify cache-control header values before storing if (HeaderUtils.containsNoStore(page.getWebResponse())) { page_ = null; } else { page_ = new SoftReference<>(page); } final WebRequest request = page.getWebResponse().getWebRequest(); webRequest_ = new WebRequest(request.getUrl(), request.getHttpMethod()); webRequest_.setRequestParameters(request.getRequestParameters()); }
private HistoryEntry(final Page page) { // verify cache-control header values before storing if (HeaderUtils.containsNoStore(page.getWebResponse())) { page_ = null; } else { page_ = new SoftReference<>(page); } final WebRequest request = page.getWebResponse().getWebRequest(); webRequest_ = new WebRequest(request.getUrl(), request.getHttpMethod()); webRequest_.setRequestParameters(request.getRequestParameters()); }
private WebResponse makeWebResponseForDataUrl(final WebRequest webRequest) throws IOException { final URL url = webRequest.getUrl(); final List<NameValuePair> responseHeaders = new ArrayList<>(); final DataURLConnection connection; try { connection = new DataURLConnection(url); } catch (final DecoderException e) { throw new IOException(e.getMessage()); } responseHeaders.add(new NameValuePair(HttpHeader.CONTENT_TYPE_LC, connection.getMediaType() + ";charset=" + connection.getCharset())); try (InputStream is = connection.getInputStream()) { final DownloadedContent downloadedContent = HttpWebConnection.downloadContent(is, getOptions().getMaxInMemory()); final WebResponseData data = new WebResponseData(downloadedContent, 200, "OK", responseHeaders); return new WebResponse(data, url, webRequest.getHttpMethod(), 0); } }
/** * Builds a WebResponse with new content, preserving all other information. * @param wr the web response to adapt * @param newContent the new content to place in the response * @return a web response with the new content * @throws IOException if an encoding problem occurred */ protected WebResponse replaceContent(final WebResponse wr, final String newContent) throws IOException { final byte[] body = newContent.getBytes(wr.getContentCharset()); final WebResponseData wrd = new WebResponseData(body, wr.getStatusCode(), wr.getStatusMessage(), wr.getResponseHeaders()); return new WebResponse(wrd, wr.getWebRequest().getUrl(), wr.getWebRequest().getHttpMethod(), wr.getLoadTime()); }
/** * Builds a WebResponse with new content, preserving all other information. * @param wr the web response to adapt * @param newContent the new content to place in the response * @return a web response with the new content * @throws IOException if an encoding problem occurred */ protected WebResponse replaceContent(final WebResponse wr, final String newContent) throws IOException { final byte[] body = newContent.getBytes(wr.getContentCharset()); final WebResponseData wrd = new WebResponseData(body, wr.getStatusCode(), wr.getStatusMessage(), wr.getResponseHeaders()); return new WebResponse(wrd, wr.getWebRequest().getUrl(), wr.getWebRequest().getHttpMethod(), wr.getLoadTime()); }