Skip to content

Commit 85428dc

Browse files
committed
PURGE
1 parent f5538d8 commit 85428dc

File tree

11 files changed

+5
-602
lines changed

11 files changed

+5
-602
lines changed

bench/src/main/scala/org/http4s/bench/BytesBench.scala

Lines changed: 0 additions & 55 deletions
This file was deleted.

blaze-core/src/main/scala/org/http4s/blazecore/util/EntityBodyWriter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private[http4s] trait EntityBodyWriter[F[_]] {
1515
/** The `ExecutionContext` on which to run computations, assumed to be stack safe. */
1616
implicit protected def ec: ExecutionContext
1717

18-
/** Write a ByteVector to the wire.
18+
/** Write a Chunk to the wire.
1919
* If a request is cancelled, or the stream is closed this method should
2020
* return a failed Future with Cancelled as the exception
2121
*

build.sbt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ lazy val core = libraryProject("core")
2525
cats,
2626
catsEffect,
2727
fs2Io,
28-
fs2Scodec,
2928
http4sWebsocket,
3029
log4s,
3130
macroCompat,
3231
parboiled,
3332
scalaReflect(scalaOrganization.value, scalaVersion.value) % "provided",
34-
scodecBits,
3533
scalaCompiler(scalaOrganization.value, scalaVersion.value) % "provided"
3634
),
3735
macroParadiseSetting

core/src/main/scala/org/http4s/multipart/MultipartDecoder.scala

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package multipart
33

44
import cats.effect._
55
import cats.implicits._
6-
import fs2._
7-
import fs2.interop.scodec.ByteVectorChunk
8-
import scodec.bits.ByteVector
96

107
private[http4s] object MultipartDecoder {
118

@@ -31,32 +28,4 @@ private[http4s] object MultipartDecoder {
3128
}
3229
}
3330

34-
def gatherParts[F[_]]: Pipe[F, Either[Headers, ByteVector], Part[F]] = s => {
35-
def go(part: Part[F], lastWasLeft: Boolean)(s: Stream[F, Either[Headers, ByteVector]])
36-
: Pull[F, Part[F], Option[Either[Headers, ByteVector]]] =
37-
s.pull.uncons1.flatMap {
38-
case Some((Left(headers), s)) =>
39-
if (lastWasLeft) {
40-
go(
41-
Part(Headers(part.headers.toList ::: headers.toList), EmptyBody),
42-
lastWasLeft = true)(s)
43-
} else {
44-
Pull.output1(part) >> go(Part(headers, EmptyBody), lastWasLeft = true)(s)
45-
}
46-
case Some((Right(bv), s)) =>
47-
go(
48-
part.copy(body = part.body.append(Stream.chunk(ByteVectorChunk(bv)))),
49-
lastWasLeft = false)(s)
50-
case None =>
51-
Pull.output1(part) >> Pull.pure(None)
52-
}
53-
54-
s.pull.uncons1.flatMap {
55-
case Some((Left(headers), s)) => go(Part(headers, EmptyBody), lastWasLeft = true)(s)
56-
case Some((Right(byte @ _), _)) =>
57-
Pull.raiseError(InvalidMessageBodyFailure("No headers in first part"))
58-
case None => Pull.pure(None)
59-
}.stream
60-
}
61-
6231
}

core/src/main/scala/org/http4s/multipart/MultipartParser.scala

Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -4,157 +4,11 @@ package multipart
44
import cats.effect._
55
import cats.implicits.{catsSyntaxEither => _, _}
66
import fs2._
7-
import scala.annotation.tailrec
8-
import scodec.bits.ByteVector
97
import org.http4s.util._
108

119
/** A low-level multipart-parsing pipe. Most end users will prefer EntityDecoder[Multipart]. */
1210
object MultipartParser {
1311

14-
private[this] val logger = org.log4s.getLogger
15-
16-
private val CRLFBytes = ByteVector('\r', '\n')
17-
private val DashDashBytes = ByteVector('-', '-')
18-
private val boundaryBytes: Boundary => ByteVector = boundary =>
19-
ByteVector(boundary.value.getBytes)
20-
private val startLineBytes: Boundary => ByteVector = boundaryBytes.andThen(DashDashBytes ++ _)
21-
private val endLineBytes: Boundary => ByteVector = startLineBytes.andThen(_ ++ DashDashBytes)
22-
private val expectedBytes: Boundary => ByteVector = startLineBytes.andThen(CRLFBytes ++ _)
23-
24-
final case class Out[+A](a: A, tail: Option[ByteVector] = None)
25-
26-
def parse[F[_]: Sync](boundary: Boundary): Pipe[F, Byte, Either[Headers, ByteVector]] = s => {
27-
val bufferedMultipartT = s.compile.toVector.map(ByteVector(_))
28-
val parts = bufferedMultipartT.flatMap(parseToParts(_)(boundary))
29-
val listT = parts.map(splitParts(_)(boundary)(List.empty[Either[Headers, ByteVector]]))
30-
31-
Stream
32-
.eval(listT)
33-
.flatMap(list => Stream.emits(list))
34-
}
35-
36-
/**
37-
* parseToParts - Removes Prelude and Trailer
38-
*
39-
* splitParts - Splits Into Parts
40-
* splitPart - Takes a Single Part of the Front
41-
* generatePart - Generates a tuple of Headers and a ByteVector of the Body, effectively a Part
42-
*
43-
* generateHeaders - Generate Headers from ByteVector
44-
* splitHeader - Splits a Header into the Name and Value
45-
*/
46-
def parseToParts[F[_]](byteVector: ByteVector)(boundary: Boundary)(
47-
implicit F: Sync[F]): F[ByteVector] = {
48-
val startLine = startLineBytes(boundary)
49-
val startIndex = byteVector.indexOfSlice(startLine)
50-
val endLine = endLineBytes(boundary)
51-
val endIndex = byteVector.indexOfSlice(endLine)
52-
53-
if (startIndex >= 0 && endIndex >= 0) {
54-
val parts = byteVector.slice(
55-
startIndex + startLine.length + CRLFBytes.length,
56-
endIndex - CRLFBytes.length)
57-
F.delay(parts)
58-
} else {
59-
F.raiseError(MalformedMessageBodyFailure("Expected a multipart start or end line"))
60-
}
61-
}
62-
63-
def splitPart(byteVector: ByteVector)(boundary: Boundary): Option[(ByteVector, ByteVector)] = {
64-
val expected = expectedBytes(boundary)
65-
val index = byteVector.indexOfSlice(expected)
66-
67-
if (index >= 0L) {
68-
val (part, restWithExpected) = byteVector.splitAt(index)
69-
val rest = restWithExpected.drop(expected.length)
70-
Option((part, rest))
71-
} else {
72-
Option((byteVector, ByteVector.empty))
73-
}
74-
}
75-
@tailrec
76-
def splitParts(byteVector: ByteVector)(boundary: Boundary)(
77-
acc: List[Either[Headers, ByteVector]]): List[Either[Headers, ByteVector]] = {
78-
79-
val expected = expectedBytes(boundary)
80-
val containsExpected = byteVector.containsSlice(expected)
81-
82-
val partOpt = if (!containsExpected) {
83-
84-
Option((byteVector, ByteVector.empty))
85-
} else {
86-
splitPart(byteVector)(boundary)
87-
}
88-
89-
partOpt match {
90-
case Some((part, rest)) =>
91-
logger.trace(s"splitParts part: ${part.decodeUtf8.toOption}")
92-
93-
val (headers, body) = generatePart(part)
94-
95-
val newAcc = Either.right(body) :: Either.left(headers) :: acc
96-
logger.trace(s"splitParts newAcc: $newAcc")
97-
98-
if (rest.isEmpty) {
99-
newAcc.reverse
100-
} else {
101-
splitParts(rest)(boundary)(newAcc)
102-
}
103-
case None => acc.reverse
104-
}
105-
}
106-
107-
def generatePart(byteVector: ByteVector): (Headers, ByteVector) = {
108-
val doubleCRLF = CRLFBytes ++ CRLFBytes
109-
val index = byteVector.indexOfSlice(doubleCRLF)
110-
// Each Part Should Contain this Separation between bodies and headers -- We could handle failure.
111-
val (headersSplit, bodyWithCRLFs) = byteVector.splitAt(index)
112-
val body = bodyWithCRLFs.drop(doubleCRLF.length)
113-
114-
logger.trace(s"GeneratePart HeadersSplit ${headersSplit.decodeAscii}")
115-
logger.trace(s"GenerateParts Body ${body.decodeAscii}")
116-
117-
val headers = generateHeaders(headersSplit ++ CRLFBytes)(Headers.empty)
118-
119-
(headers, body)
120-
}
121-
122-
@tailrec
123-
def generateHeaders(byteVector: ByteVector)(acc: Headers): Headers = {
124-
val headerO = splitHeader(byteVector)
125-
126-
headerO match {
127-
case Some((lineBV, rest)) =>
128-
val headerO = for {
129-
line <- lineBV.decodeAscii.right.toOption
130-
idx <- Some(line.indexOf(':'))
131-
if idx >= 0
132-
header = Header(line.substring(0, idx), line.substring(idx + 1).trim)
133-
} yield header
134-
135-
val newHeaders = acc ++ headerO
136-
137-
logger.trace(s"Generate Headers Header0 = $headerO")
138-
generateHeaders(rest)(newHeaders)
139-
case None => acc
140-
}
141-
142-
}
143-
144-
def splitHeader(byteVector: ByteVector): Option[(ByteVector, ByteVector)] = {
145-
val index = byteVector.indexOfSlice(CRLFBytes)
146-
147-
if (index >= 0L) {
148-
val (line, rest) = byteVector.splitAt(index)
149-
150-
logger.trace(s"Split Header Line: ${line.decodeAscii}")
151-
logger.trace(s"Split Header Rest: ${rest.decodeAscii}")
152-
Option((line, rest.drop(CRLFBytes.length)))
153-
} else {
154-
Option.empty[(ByteVector, ByteVector)]
155-
}
156-
}
157-
15812
private val CRLFBytesN = Array[Byte]('\r', '\n')
15913
private val DoubleCRLFBytesN = Array[Byte]('\r', '\n', '\r', '\n')
16014
private val DashDashBytesN = Array[Byte]('-', '-')

docs/src/main/tut/dsl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Ok("Ok response.").map(_.removeCookie("foo")).unsafeRunSync.headers
180180

181181
Most status codes take an argument as a body. In http4s, `Request[F]`
182182
and `Response[F]` bodies are represented as a
183-
`fs2.Stream[F, ByteVector]`. It's also considered good
183+
`fs2.Stream[F, Byte]`. It's also considered good
184184
HTTP manners to provide a `Content-Type` and, where known in advance,
185185
`Content-Length` header in one's responses.
186186

examples/src/main/scala/com/example/http4s/ScienceExperiments.scala

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,6 @@ class ScienceExperiments[F[_]] extends Http4sDsl[F] {
125125
val body = scheduler.awakeEvery[F](2.seconds).zipWith(Stream.emits(resp))((_, c) => c)
126126
Ok(body)
127127

128-
/*
129-
case req @ POST -> Root / "ill-advised-echo" =>
130-
// Reads concurrently from the input. Don't do this at home.
131-
implicit val byteVectorMonoidInstance: Monoid[ByteVector] = new Monoid[ByteVector]{
132-
def combine(x: ByteVector, y: ByteVector): ByteVector = x ++ y
133-
def empty: ByteVector = ByteVector.empty
134-
}
135-
val seq = 1 to Runtime.getRuntime.availableProcessors
136-
val f: Int => IO[ByteVector] = _ => req.body.map(ByteVector.fromByte).compile.toVector.map(_.combineAll)
137-
val result: Stream[IO, Byte] = Stream.eval(IO.traverse(seq)(f))
138-
.flatMap(v => Stream.emits(v.combineAll.toSeq))
139-
Ok(result)
140-
*/
141-
142128
case GET -> Root / "fail" / "task" =>
143129
F.raiseError(new RuntimeException)
144130

project/Http4sPlugin.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ object Http4sPlugin extends AutoPlugin {
267267
lazy val discipline = "org.typelevel" %% "discipline" % "0.9.0"
268268
lazy val fs2Io = "co.fs2" %% "fs2-io" % "0.10.3"
269269
lazy val fs2ReactiveStreams = "com.github.zainab-ali" %% "fs2-reactive-streams" % "0.5.1"
270-
lazy val fs2Scodec = "co.fs2" %% "fs2-scodec" % fs2Io.revision
271270
lazy val gatlingTest = "io.gatling" % "gatling-test-framework" % "2.3.1"
272271
lazy val gatlingHighCharts = "io.gatling.highcharts" % "gatling-charts-highcharts" % gatlingTest.revision
273272
lazy val http4sWebsocket = "org.http4s" %% "http4s-websocket" % "0.2.0"
@@ -293,7 +292,6 @@ object Http4sPlugin extends AutoPlugin {
293292
def scalaCompiler(so: String, sv: String) = so % "scala-compiler" % sv
294293
def scalaReflect(so: String, sv: String) = so % "scala-reflect" % sv
295294
lazy val scalaXml = "org.scala-lang.modules" %% "scala-xml" % "1.1.0"
296-
lazy val scodecBits = "org.scodec" %% "scodec-bits" % "1.1.5"
297295
lazy val specs2Core = "org.specs2" %% "specs2-core" % "4.0.3"
298296
lazy val specs2MatcherExtra = "org.specs2" %% "specs2-matcher-extra" % specs2Core.revision
299297
lazy val specs2Scalacheck = "org.specs2" %% "specs2-scalacheck" % specs2Core.revision

testing/src/test/scala/org/http4s/Http4sSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ trait Http4sSpec
7878
.map(_.getOrElse(""))
7979
.unsafeRunSync
8080

81-
def writeToByteVector[A](a: A)(implicit W: EntityEncoder[IO, A]): Chunk[Byte] =
81+
def writeToChunk[A](a: A)(implicit W: EntityEncoder[IO, A]): Chunk[Byte] =
8282
Stream
8383
.emit(W.toEntity(a))
8484
.covary[IO]

0 commit comments

Comments
 (0)