Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JDK 11 HttpClient #158

Merged
merged 5 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['8', '17']
java: ['11', '17']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
Expand All @@ -34,7 +34,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
java-version: 11
- name: Check Binary Compatibility
run: ./mill -i __.mimaReportBinaryIssues

Expand All @@ -55,7 +55,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
java-version: 11
- name: Publish to Maven Central
run: |
if [[ $(git tag --points-at HEAD) != '' ]]; then
Expand Down
8 changes: 3 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,9 @@ know.
As it turns out, Kenneth Reitz's Requests is
[not a lot of code](https://github.com/requests/requests/tree/main/requests).
Most of the heavy lifting is done in other libraries, and his library is a just
thin-shim that makes the API 10x better. It turns out on the JVM most of the
heavy lifting is also done for you, by `java.net.HttpUrlConnection` in the
simplest case, and other libraries like
[AsyncHttpClient](https://github.com/AsyncHttpClient/async-http-client) for more
advanced use cases.
thin-shim that makes the API 10x better. Similarly, it turns out on the JVM most of the
heavy lifting is also done for you. There have always been options, but
since JDK 11 a decent HTTP client is provided in the standard library.

Given that's the case, how hard can it be to port over a dozen Python files to
Scala? This library attempts to do that: class by class, method by method,
Expand Down
31 changes: 18 additions & 13 deletions requests/src/requests/Model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ case class Request(url: String,

/**
* Represents the different things you can upload in the body of a HTTP
* request. By default allows form-encoded key-value pairs, arrays of bytes,
* strings, files, and inputstreams. These types can be passed directly to
* request. By default, allows form-encoded key-value pairs, arrays of bytes,
* strings, files, and InputStreams. These types can be passed directly to
* the `data` parameter of [[Requester.apply]] and will be wrapped automatically
* by the implicit constructors.
*/
Expand All @@ -76,6 +76,7 @@ trait RequestBlob{
object RequestBlob{
object EmptyRequestBlob extends RequestBlob{
def write(out: java.io.OutputStream): Unit = ()
override def headers = Seq("Content-Length" -> "0")
}

implicit class ByteSourceRequestBlob[T](x: T)(implicit f: T => geny.Writable) extends RequestBlob{
Expand Down Expand Up @@ -176,18 +177,21 @@ class ResponseBlob(val bytes: Array[Byte]){


/**
* Represents a HTTP response
*
* @param url the URL that the original request was made to
* @param statusCode the status code of the response
* @param statusMessage the status message of the response
* @param headers the raw headers the server sent back with the response
* @param data the response body; may contain HTML, JSON, or binary or textual data
* @param history the response of any redirects that were performed before
* arriving at the current response
*/
* Represents a HTTP response
*
* @param url the URL that the original request was made to
* @param statusCode the status code of the response
* @param statusMessage a string that describes the status code.
* This is not the reason phrase sent by the server,
* but a string describing [[statusCode]], as hardcoded in this library
* @param headers the raw headers the server sent back with the response
* @param data the response body; may contain HTML, JSON, or binary or textual data
* @param history the response of any redirects that were performed before
* arriving at the current response
*/
case class Response(url: String,
statusCode: Int,
@deprecated("Value is inferred from `statusCode`", "0.9.0")
statusMessage: String,
data: geny.Bytes,
headers: Map[String, Seq[String]],
Expand Down Expand Up @@ -222,11 +226,12 @@ case class Response(url: String,
f(new java.io.ByteArrayInputStream(data.array))
}
override def httpContentType: Option[String] = contentType
override def contentLength: Option[Long] = Some(data.array.size)
override def contentLength: Option[Long] = Some(data.array.length)
}

case class StreamHeaders(url: String,
statusCode: Int,
@deprecated("Value is inferred from `statusCode`", "0.9.0")
statusMessage: String,
headers: Map[String, Seq[String]],
history: Option[Response]){
Expand Down
Loading
Loading