sguzman / RemoteWeb

A Proxy web webserver in scala that reroutes RESTful API calls
The Unlicense
0 stars 1 forks source link

Copy body from request to request #2

Open sguzman opened 6 years ago

sguzman commented 6 years ago

Currently, I am using lolhttp for HTTP backend needs. I haven't used it very much so I am unfamiliar with how to use it in specific cases.

I do not know how to copy the body of a request into a string. This is necessary so the body can be copied and pasted into the proxy request.

Thus, the goal of this ticket is to figure out how to copy contents of a request into a string. Once that is done, it should be carried over into the proxy request to allow the proxy client to be able to proxy over body contents as well.

joyoyoyoyoyo commented 6 years ago

Maybe if we use the content-type and content-length from the message HTTP headers to handle how to read in the bytes from the HTTP request, we can then handle the bytes are read from the body.

For example if the MIME type is a jpg image, then we know that we'd have to read in that MIME type from the byte stream or bytes array structure and then handle how those are encoded. Since it would be a byte array or chunk, then a MIME type of jpg might just look like gibberish as a string.

But if the http-content header is text/plain, then encoding and receiving the byte array as a String would show as a human interpretable file encoded in a string value.

As for the API. they might have some method using their readAs function or working with their content value in request.scala

Fast approach would be to use similar code from: core/src/test/scala/ContentTests.scala

joyoyoyoyoyo commented 6 years ago

I have the response, but I can't push to the remote repo. I don't think I have write access

sguzman commented 6 years ago

I think you have to accept invitation. Also, I left a comment on your code changes