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

akka-http-core: bug in 100-continue support and forms #1269

Closed
daddykotex opened this issue Jul 5, 2017 · 1 comment
Closed

akka-http-core: bug in 100-continue support and forms #1269

daddykotex opened this issue Jul 5, 2017 · 1 comment
Labels
0 - new Ticket is unclear on it's purpose or if it is valid or not bug help wanted Identifies issues that the core team will likely not have time to work on t:core Issues related to the akka-http-core module t:server Issues related to the HTTP server
Milestone

Comments

@daddykotex
Copy link
Contributor

daddykotex commented Jul 5, 2017

If you define a simple service with a route to handle form submission, you can have issue if the client send the request in two pieces using the Expect header. Given this server:

package example

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer

import scala.io.StdIn

object AkkaHttp extends App {

  implicit val system = ActorSystem("my-system")
  implicit val materializer = ActorMaterializer()
  // needed for the future flatMap/onComplete in the end
  implicit val executionContext = system.dispatcher

  val route = post {
    path("path") {
      formField("grant_type" ! "example", 'value1, 'value2) { (value1, value2) =>
        complete(StatusCodes.OK)
      }
    }
  }

  val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)

  println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
  
  StdIn.readLine() // let it run until user presses return
  bindingFuture
    .flatMap(_.unbind()) // trigger unbinding from the port
    .onComplete(_ => system.terminate()) // and shutdown when done
}

This query does not works:

curl -v -H "Content-Type: application/x-www-form-urlencoded" 'http://localhost:8080/path' -d 'grant_type=example&value1=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&value2=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /path HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.51.0
> Accept: */*
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 1032
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< Server: akka-http/10.0.9
< Date: Thu, 29 Jun 2017 13:26:23 GMT
* We are completely uploaded and fine
< HTTP/1.1 400 Bad Request
< Server: akka-http/10.0.9
< Date: Thu, 29 Jun 2017 13:26:23 GMT
< Content-Type: text/plain; charset=UTF-8
< Content-Length: 93
<
The form field 'value1' was malformed:
* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact
Substream Source cannot be materialized more than once

This one works (note the -H 'Expect: '):

curl -v -H 'Expect: ' -H "Content-Type: application/x-www-form-urlencoded" 'http://localhost:8080/path' -d 'grant_type=example&value1=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&value2=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /path HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.51.0
> Accept: */*
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 1032
> Expect: 
>
* upload completely sent off: 1032 out of 1032 bytes
< HTTP/1.1 200 OK
< Server: akka-http/10.0.9
< Date: Thu, 29 Jun 2017 13:22:42 GMT
< Content-Type: text/plain; charset=UTF-8
< Content-Length: 2
<
* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact
OK

I suppose the 100-continue support is broken when handling forms.

Coming from: #143 (comment)

@jrudolph jrudolph added 0 - new Ticket is unclear on it's purpose or if it is valid or not bug help wanted Identifies issues that the core team will likely not have time to work on t:core Issues related to the akka-http-core module t:server Issues related to the HTTP server labels Jul 17, 2017
@jrudolph
Copy link
Contributor

Thanks, @daddykotex. I investigated this a bit and it seems this is a duplicate of long-standing #73. I'll close it as a duplicate here but see it as a reminder that #73 finally needs a resolution.

Duplicate of #73.

@jrudolph jrudolph marked this as a duplicate of #73 Jul 17, 2017
@jrudolph jrudolph added this to the duplicate milestone Jul 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 - new Ticket is unclear on it's purpose or if it is valid or not bug help wanted Identifies issues that the core team will likely not have time to work on t:core Issues related to the akka-http-core module t:server Issues related to the HTTP server
Projects
None yet
Development

No branches or pull requests

2 participants