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

ProtocolError: malformed MIME header initial line #40

Closed
reggi opened this issue Dec 22, 2018 · 7 comments
Closed

ProtocolError: malformed MIME header initial line #40

reggi opened this issue Dec 22, 2018 · 7 comments

Comments

@reggi
Copy link

reggi commented Dec 22, 2018

I'm sending over a POST request and I think it's confusing the body for the header.

ProtocolError: malformed MIME header initial line: "query": "{ hello }",

@kevinkassimo
Copy link
Contributor

Could you post the raw response that triggers this error?

@reggi
Copy link
Author

reggi commented Dec 22, 2018

{
  "query": "{ hello }",
  "operationName": "",
  "variables": {}
}

@kevinkassimo
Copy link
Contributor

kevinkassimo commented Dec 22, 2018

Sorry, but can you also include the headers and request line along with the request body (and especially any whitespace or CRLF characters between them)? I want to investigate where actually did the readMIMEHeader() fail...

@kevinkassimo
Copy link
Contributor

kevinkassimo commented Dec 22, 2018

Actually, have you sent the request correctly? Because it seems as if it is treating "query": "{ hello }", as the initial header line, which should only happen when it reads the first body line { as the first request line (which should be GET / HTTP/1.1 or something similar)... (looks as if no request line nor headers are sent along with the body...)

@reggi
Copy link
Author

reggi commented Dec 27, 2018

Here's the full request:

POST 8000
Content-Type: application/json
cache-control: no-cache
Postman-Token: c32b827f-bcfc-4c78-ac19-b98b6998bc61
User-Agent: PostmanRuntime/7.4.0
Accept: */*
Host: localhost:8000
accept-encoding: gzip, deflate
content-length: 68
{ "query": "{ hello }", "operationName": "", "variables": "" }
HTTP/1.1 200
status: 200
content-length: 47
{ "data": { "hello": "Hello world!" } }

Here's the full error:

ProtocolError: malformed MIME header initial line:   "query": "{ hello }",
    at ProtocolError (file:///Users/thomas.reggi/.deno/deps/https/deno.land/x/net/textproto.ts:20:5)
    at readMIMEHeader (file:///Users/thomas.reggi/.deno/deps/https/deno.land/x/net/textproto.ts:68:13)

Seems to be responding correctly but still failing.

@bartlomieju
Copy link
Member

I managed to reproduce this issue, and it turns out this problem arises if you try to respond to request without reading its body.

http_bench.ts

import * as deno from "deno";
import { serve } from "./http.ts";

const addr = deno.args[1] || "127.0.0.1:4500";
const server = serve(addr);

const body = new TextEncoder().encode("Hello World");

async function main(): Promise<void> {
  for await (const request of server) {
    await request.body() // adding this line prevent ProtocolError
    await request.respond({ status: 200, body });
  }
}

main();

I guess a check is needed in request.respond that ensures whole requests has been read.

@bartlomieju
Copy link
Member

I believe this was resolved in #49, can we close this now?

@ry ry closed this as completed May 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants