Class RequestImpl

    • Constructor Detail

      • RequestImpl

        RequestImpl​(ChannelOwner parent,
                    java.lang.String type,
                    java.lang.String guid,
                    com.google.gson.JsonObject initializer)
    • Method Detail

      • allHeaders

        public java.util.Map<java.lang.String,​java.lang.String> allHeaders()
        Description copied from interface: Request
        An object with all the request HTTP headers associated with this request. The header names are lower-cased.
        Specified by:
        allHeaders in interface Request
      • failure

        public java.lang.String failure()
        Description copied from interface: Request
        The method returns null unless this request has failed, as reported by requestfailed event.

        **Usage**

        Example of logging of all the failed requests:

        
         page.onRequestFailed(request -> {
           System.out.println(request.url() + " " + request.failure());
         });
         
        Specified by:
        failure in interface Request
      • frame

        public FrameImpl frame()
        Description copied from interface: Request
        Returns the Frame that initiated this request.

        **Usage**

        
         String frameUrl = request.frame().url();
         

        **Details**

        Note that in some cases the frame is not available, and this method will throw.

        • When request originates in the Service Worker. You can use request.serviceWorker() to check that.
        • When navigation request is issued before the corresponding frame is created. You can use Request.isNavigationRequest() to check that.

        Here is an example that handles all the cases:

        Specified by:
        frame in interface Request
      • headers

        public java.util.Map<java.lang.String,​java.lang.String> headers()
        Description copied from interface: Request
        An object with the request HTTP headers. The header names are lower-cased. Note that this method does not return security-related headers, including cookie-related ones. You can use Request.allHeaders() for complete list of headers that include cookie information.
        Specified by:
        headers in interface Request
      • headersArray

        public java.util.List<HttpHeader> headersArray()
        Description copied from interface: Request
        An array with all the request HTTP headers associated with this request. Unlike Request.allHeaders(), header names are NOT lower-cased. Headers with multiple entries, such as Set-Cookie, appear in the array multiple times.
        Specified by:
        headersArray in interface Request
      • headerValue

        public java.lang.String headerValue​(java.lang.String name)
        Description copied from interface: Request
        Returns the value of the header matching the name. The name is case insensitive.
        Specified by:
        headerValue in interface Request
        Parameters:
        name - Name of the header.
      • isNavigationRequest

        public boolean isNavigationRequest()
        Description copied from interface: Request
        Whether this request is driving frame's navigation.

        Some navigation requests are issued before the corresponding frame is created, and therefore do not have Request.frame() available.

        Specified by:
        isNavigationRequest in interface Request
      • method

        public java.lang.String method()
        Description copied from interface: Request
        Request's method (GET, POST, etc.)
        Specified by:
        method in interface Request
      • postData

        public java.lang.String postData()
        Description copied from interface: Request
        Request's post body, if any.
        Specified by:
        postData in interface Request
      • postDataBuffer

        public byte[] postDataBuffer()
        Description copied from interface: Request
        Request's post body in a binary form, if any.
        Specified by:
        postDataBuffer in interface Request
      • redirectedFrom

        public Request redirectedFrom()
        Description copied from interface: Request
        Request that was redirected by the server to this one, if any.

        When the server responds with a redirect, Playwright creates a new Request object. The two requests are connected by redirectedFrom() and redirectedTo() methods. When multiple server redirects has happened, it is possible to construct the whole redirect chain by repeatedly calling redirectedFrom().

        **Usage**

        For example, if the website http://example.com redirects to https://example.com:

        
         Response response = page.navigate("http://example.com");
         System.out.println(response.request().redirectedFrom().url()); // "http://example.com"
         

        If the website https://google.com has no redirects:

        
         Response response = page.navigate("https://google.com");
         System.out.println(response.request().redirectedFrom()); // null
         
        Specified by:
        redirectedFrom in interface Request
      • redirectedTo

        public Request redirectedTo()
        Description copied from interface: Request
        New request issued by the browser if the server responded with redirect.

        **Usage**

        This method is the opposite of Request.redirectedFrom():

        
         System.out.println(request.redirectedFrom().redirectedTo() == request); // true
         
        Specified by:
        redirectedTo in interface Request
      • resourceType

        public java.lang.String resourceType()
        Description copied from interface: Request
        Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the following: document, stylesheet, image, media, font, script, texttrack, xhr, fetch, eventsource, websocket, manifest, other.
        Specified by:
        resourceType in interface Request
      • response

        public ResponseImpl response()
        Description copied from interface: Request
        Returns the matching Response object, or null if the response was not received due to error.
        Specified by:
        response in interface Request
      • sizes

        public Sizes sizes()
        Description copied from interface: Request
        Returns resource size information for given request.
        Specified by:
        sizes in interface Request
      • timing

        public Timing timing()
        Description copied from interface: Request
        Returns resource timing information for given request. Most of the timing values become available upon the response, responseEnd becomes available when request finishes. Find more information at Resource Timing API.

        **Usage**

        
         page.onRequestFinished(request -> {
           Timing timing = request.timing();
           System.out.println(timing.responseEnd - timing.startTime);
         });
         page.navigate("http://example.com");
         
        Specified by:
        timing in interface Request
      • url

        public java.lang.String url()
        Description copied from interface: Request
        URL of the request.
        Specified by:
        url in interface Request
      • finalRequest

        Request finalRequest()
      • getRawHeaders

        private RawHeaders getRawHeaders()