From ea91ca6074d372bf0005d7b9cdf34fa9a66df9e4 Mon Sep 17 00:00:00 2001 From: Gregory Travis Date: Mon, 3 Mar 2025 15:49:48 -0500 Subject: [PATCH 1/3] http green --- .../Base/0.0.0-dev/src/Network/HTTP.enso | 2 +- .../0.0.0-dev/src/Network/HTTP/Response.enso | 26 +++++++++++++++---- .../src/Network/HTTP/Response_Body.enso | 7 ++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP.enso index 3fb6614acf27..be2df68dd57c 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP.enso @@ -166,7 +166,7 @@ type HTTP all_headers = headers + boundary_header_list mapped_headers = all_headers.map on_problems=No_Wrap.Value .to_java_pair - response = Response.Value (EnsoSecretHelper.makeRequest (self.make_client self resolved_body.hash) builder req.uri.to_java_representation mapped_headers (cache_policy.should_use_cache req)) + response = Response.new (EnsoSecretHelper.makeRequest (self.make_client self resolved_body.hash) builder req.uri.to_java_representation mapped_headers (cache_policy.should_use_cache req)) if error_on_failure_code.not || response.code.is_success then response else body = response.body.decode_as_text.catch Any _->"" message = if body.is_empty then Nothing else body diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Response.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Response.enso index 2b09db5597f8..a94f81e06b2d 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Response.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Response.enso @@ -9,6 +9,7 @@ import project.Data.Vector.Vector import project.Error.Error import project.Errors.File_Error.File_Error import project.Network.HTTP.Header.Header +import project.Network.HTTP.HTTP_Error.HTTP_Error import project.Network.HTTP.HTTP_Status_Code.HTTP_Status_Code import project.Network.HTTP.Response_Body.Response_Body import project.Network.URI.URI @@ -20,6 +21,7 @@ import project.System.File_Format.Auto_Detect import project.System.File_Format.File_Format import project.System.File_Format.Infer import project.System.File_Format_Metadata.File_Format_Metadata +import project.System.Input_Stream.Input_Stream from project.Data.Text.Extensions import all from project.Metadata import Display, Widget from project.Network.HTTP.Response_Body import decode_format_selector @@ -38,7 +40,11 @@ type Response response. - body_object: The body of the response. If nothing will be read from the internal_http_response. Allows for materialization. - Value internal_http_response body_object=Nothing + Value internal_http_response:Enso_Http_Response body_object=Nothing + + ## PRIVATE + new java_http_response:EnsoHttpResponse = + Response.Value (Enso_Http_Response.new java_http_response) ## PRIVATE Creates a new Response with the body materialized. @@ -50,9 +56,7 @@ type Response ICON metadata Get the uri for the response. uri : URI - uri self = - uri_string = self.internal_http_response.uri.toString - URI.parse uri_string + uri self = self.internal_http_response.uri ## GROUP Metadata ICON metadata @@ -126,7 +130,7 @@ type Response example_code = Examples.get_response.code code : HTTP_Status_Code - code self = HTTP_Status_Code.Value self.internal_http_response.statusCode + code self = HTTP_Status_Code.Value self.internal_http_response.status_code ## ALIAS parse GROUP Conversions @@ -238,3 +242,15 @@ filename_from_content_disposition content_disposition = content_disposition.if_not_nothing <| match = 'filename="(.*)"'.to_regex.match content_disposition match.if_not_nothing <| match.get 1 + +## PRIVATE + After an `EnsoHttpResponse` has been returned from Java to Enos, it should be + converted to this, which takes care of ensuring that the body `InputStream` + is wrapped as a `Managed_Resource`. +type Enso_Http_Response + private Value uri:URI (headers:HttpHeaders) body:Input_Stream status_code:Integer + + new java_response:EnsoHttpResponse -> Enso_Http_Response = + uri = URI.parse java_response.uri.toString + error_handler = (HTTP_Error.handle_java_exceptions uri) + Enso_Http_Response.Value uri java_response.headers (Input_Stream.new java_response.body error_handler) java_response.statusCode diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Response_Body.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Response_Body.enso index 31cd11eda675..d1cd5c494696 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Response_Body.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Response_Body.enso @@ -36,8 +36,6 @@ from project.Metadata.Choice import Option from project.Metadata.Widget import Single_Choice from project.System.File_Format import format_types -polyglot java import java.io.InputStream - ## PRIVATE How large a response body can be before it is written to a temporary file. maximum_body_in_memory = 4192 @@ -51,9 +49,8 @@ type Response_Body - stream: The body of the response as an InputStream. - metadata: File format metadata associated with the response. - uri: The URI of the response. - new : InputStream -> File_Format_Metadata -> URI -> Response_Body - new stream (metadata : File_Format_Metadata) (uri : URI) = - input_stream = Input_Stream.new stream (HTTP_Error.handle_java_exceptions uri) + new : Input_Stream -> File_Format_Metadata -> URI -> Response_Body + new input_stream (metadata : File_Format_Metadata) (uri : URI) = Response_Body.Raw_Stream input_stream metadata uri ## PRIVATE From 935c30588885078423a3ee9ef415ad5ab82375bd Mon Sep 17 00:00:00 2001 From: Gregory Travis Date: Mon, 3 Mar 2025 16:13:23 -0500 Subject: [PATCH 2/3] Response ctor priate, typo --- .../Standard/Base/0.0.0-dev/src/Network/HTTP/Response.enso | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Response.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Response.enso index a94f81e06b2d..b9850e899875 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Response.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Response.enso @@ -40,7 +40,7 @@ type Response response. - body_object: The body of the response. If nothing will be read from the internal_http_response. Allows for materialization. - Value internal_http_response:Enso_Http_Response body_object=Nothing + private Value internal_http_response:Enso_Http_Response body_object=Nothing ## PRIVATE new java_http_response:EnsoHttpResponse = @@ -244,7 +244,7 @@ filename_from_content_disposition content_disposition = match.if_not_nothing <| match.get 1 ## PRIVATE - After an `EnsoHttpResponse` has been returned from Java to Enos, it should be + After an `EnsoHttpResponse` has been returned from Java to Enso, it should be converted to this, which takes care of ensuring that the body `InputStream` is wrapped as a `Managed_Resource`. type Enso_Http_Response From 91d6b9b81058a314f7f1284ab14e7d1423858dfb Mon Sep 17 00:00:00 2001 From: Gregory Travis Date: Tue, 4 Mar 2025 08:55:21 -0500 Subject: [PATCH 3/3] api --- .../Standard/Base/0.0.0-dev/docs/api/Network/HTTP/Response.md | 4 +++- .../Base/0.0.0-dev/docs/api/Network/HTTP/Response_Body.md | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/docs/api/Network/HTTP/Response.md b/distribution/lib/Standard/Base/0.0.0-dev/docs/api/Network/HTTP/Response.md index ec00f0b8e5d1..9bc5a43b2281 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/docs/api/Network/HTTP/Response.md +++ b/distribution/lib/Standard/Base/0.0.0-dev/docs/api/Network/HTTP/Response.md @@ -1,7 +1,8 @@ ## Enso Signatures 1.0 ## module Standard.Base.Network.HTTP.Response +- type Enso_Http_Response + - new java_response:Standard.Base.Network.HTTP.Response.EnsoHttpResponse -> Standard.Base.Network.HTTP.Response.Enso_Http_Response - type Response - - Value internal_http_response:Standard.Base.Any.Any body_object:Standard.Base.Any.Any= - body self -> Standard.Base.Any.Any - code self -> Standard.Base.Any.Any - content_length self -> Standard.Base.Any.Any @@ -11,6 +12,7 @@ - decode_as_text self encoding:(Standard.Base.Data.Text.Encoding.Encoding|Standard.Base.System.File_Format.Infer)= -> Standard.Base.Any.Any - get_header self name:Standard.Base.Data.Text.Text ~if_missing:Standard.Base.Any.Any= -> Standard.Base.Any.Any - headers self -> Standard.Base.Any.Any + - new java_http_response:Standard.Base.Network.HTTP.Response.EnsoHttpResponse -> Standard.Base.Any.Any - to_js_object self -> Standard.Base.Any.Any - uri self -> Standard.Base.Any.Any - with_materialized_body self -> Standard.Base.Any.Any diff --git a/distribution/lib/Standard/Base/0.0.0-dev/docs/api/Network/HTTP/Response_Body.md b/distribution/lib/Standard/Base/0.0.0-dev/docs/api/Network/HTTP/Response_Body.md index ac0abb08fe89..4b6525dafaf0 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/docs/api/Network/HTTP/Response_Body.md +++ b/distribution/lib/Standard/Base/0.0.0-dev/docs/api/Network/HTTP/Response_Body.md @@ -9,7 +9,7 @@ - decode_as_json self encoding:(Standard.Base.Data.Text.Encoding.Encoding|Standard.Base.System.File_Format.Infer)= -> Standard.Base.Any.Any - decode_as_text self encoding:(Standard.Base.Data.Text.Encoding.Encoding|Standard.Base.System.File_Format.Infer)= -> Standard.Base.Any.Any - materialize self -> Standard.Base.Any.Any - - new stream:Standard.Base.Any.Any metadata:Standard.Base.System.File_Format_Metadata.File_Format_Metadata uri:Standard.Base.Network.URI.URI -> Standard.Base.Any.Any + - new input_stream:Standard.Base.Any.Any metadata:Standard.Base.System.File_Format_Metadata.File_Format_Metadata uri:Standard.Base.Network.URI.URI -> Standard.Base.Any.Any - to_text self -> Standard.Base.Any.Any - with_stream self action:Standard.Base.Any.Any -> Standard.Base.Any.Any - write self file:Standard.Base.System.File.Generic.Writable_File.Writable_File on_existing_file:Standard.Base.Any.Any= -> Standard.Base.Any.Any