Class Response


  • public class Response
    extends java.lang.Object
    A thin wrapper around the HttpResponse class. Will only ever directly contain a HttpResponse<byte[]> - is not truly generic.
    • Constructor Summary

      Constructors 
      Constructor Description
      Response​(java.net.http.HttpResponse<byte[]> httpResponse, JythonHttpClient client)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] getBody()  
      java.net.CookieManager getCookieManager()  
      java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getHeaders()  
      java.net.http.HttpResponse<byte[]> getJavaResponse()  
      org.python.core.PyObject getJson()  
      org.python.core.PyObject getJson​(org.python.core.PyObject[] args, java.lang.String[] kwargs)
      Attempt to decode the raw byte[] this Response contains to a string with the specified charset, and then decode that string to a direct Python representation (ie, dictionaries and lists).
      Response.RequestWrapper getRequest()  
      int getStatusCode()  
      java.lang.String getText()  
      java.lang.String getText​(org.python.core.PyObject[] args, java.lang.String[] kwargs)
      Attempt to decode the raw byte[] this Response contains to a string with the specified charset.
      java.lang.String getUrl()  
      boolean isClientError()  
      boolean isGood()  
      boolean isServerError()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Response

        public Response​(java.net.http.HttpResponse<byte[]> httpResponse,
                        JythonHttpClient client)
    • Method Detail

      • getBody

        public byte[] getBody()
      • getJson

        public org.python.core.PyObject getJson()
      • getJson

        @Nonnull
        public org.python.core.PyObject getJson​(org.python.core.PyObject[] args,
                                                java.lang.String[] kwargs)
        Attempt to decode the raw byte[] this Response contains to a string with the specified charset, and then decode that string to a direct Python representation (ie, dictionaries and lists). Encoding defaults to the charset specified in the response, or StandardCharsets.UTF_8 if the response did not specify a charset.
      • getText

        public java.lang.String getText()
      • getText

        @Nonnull
        public java.lang.String getText​(org.python.core.PyObject[] args,
                                        java.lang.String[] kwargs)
        Attempt to decode the raw byte[] this Response contains to a string with the specified charset. Caches decoded bodies so they can be quickly retrieved again, per charset. Encoding defaults to the charset specified in the response, or StandardCharsets.UTF_8 if the response did not specify a charset.
      • getUrl

        public java.lang.String getUrl()
      • getHeaders

        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getHeaders()
      • getStatusCode

        public int getStatusCode()
      • isGood

        public boolean isGood()
        Returns:
        true if the response code was not any error.
      • isClientError

        public boolean isClientError()
        Returns:
        true if the response code was a 4XX error.
      • isServerError

        public boolean isServerError()
        Returns:
        true if the response code was a 5XX error.
      • getCookieManager

        public java.net.CookieManager getCookieManager()
      • getJavaResponse

        public java.net.http.HttpResponse<byte[]> getJavaResponse()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object