From 9374a456f6b60c80ed4c39feeecf1e31cd856ed9 Mon Sep 17 00:00:00 2001 From: "a.khakimov" Date: Sun, 5 May 2024 19:34:33 +0500 Subject: [PATCH] Draft: Http request with BodyInit --- tyrian/src/main/scala/tyrian/http/Http.scala | 3 +++ tyrian/src/main/scala/tyrian/http/Models.scala | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tyrian/src/main/scala/tyrian/http/Http.scala b/tyrian/src/main/scala/tyrian/http/Http.scala index ec83f6c5..8d468b7d 100644 --- a/tyrian/src/main/scala/tyrian/http/Http.scala +++ b/tyrian/src/main/scala/tyrian/http/Http.scala @@ -51,6 +51,9 @@ object Http: case (Body.PlainText(contentType, body), method) if !Set(Method.Get, Method.Head).contains(method) => headers.append("Content-Type", contentType) requestInit.body = body + case (Body.File(contentType, body), method) if !Set(Method.Get, Method.Head).contains(method) => + headers.append("Content-Type", contentType) + requestInit.body = body case _ => requestInit.headers = headers diff --git a/tyrian/src/main/scala/tyrian/http/Models.scala b/tyrian/src/main/scala/tyrian/http/Models.scala index a134f350..c2f3bb8c 100644 --- a/tyrian/src/main/scala/tyrian/http/Models.scala +++ b/tyrian/src/main/scala/tyrian/http/Models.scala @@ -1,5 +1,7 @@ package tyrian.http +import org.scalajs.dom.BodyInit + /** An Error will be returned if something goes wrong with an HTTP request. */ enum HttpError: /** A BadRequest means that the provide request was not valid for some reason. @@ -41,6 +43,7 @@ enum Body derives CanEqual: * the content of the body */ case PlainText(contentType: String, body: String) extends Body + case File(contentType: String, body: BodyInit) extends Body object Body: def html(body: String): Body = Body.PlainText("text/html", body)