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

null content-type breaks request handling #39

Closed
fiddlerwoaroof opened this issue Aug 29, 2019 · 5 comments · Fixed by #40
Closed

null content-type breaks request handling #39

fiddlerwoaroof opened this issue Aug 29, 2019 · 5 comments · Fixed by #40

Comments

@fiddlerwoaroof
Copy link

If the Content-Type header isn't passed, this code passes a content-type of NIL to HTTP-BODY:PARSE, preventing the request from being processed properly.

lack/src/request.lisp

Lines 105 to 108 in 8ddb653

(let ((parsed (http-body:parse content-type content-length raw-body)))
(when (and (consp parsed)
(every #'consp parsed))
(setf body-parameters parsed)))

This could be fixed either by adding a null check or defaulting content-type to text/plain when it's not passed.

@fukamachi
Copy link
Owner

Content-Type is thought to be required in Clack as it’s written in Lack’s README.

:content-type (Required, String)

Did you get this error with some Clack handler or situation?

@fiddlerwoaroof
Copy link
Author

fiddlerwoaroof commented Aug 29, 2019

I'm writing a backend for this: http://www.todobackend.com/client/index.html?http://localhost:5000 and I've discovered that their DELETE requests don't set the Content-Type header:

Host: localhost:5000.
Connection: keep-alive.
Pragma: no-cache.
Cache-Control: no-cache.
Accept: application/json, text/javascript, */*; q=0.01.
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.19 Safari/537.36.
Sec-Fetch-Mode: cors.
Origin: http://www.todobackend.com.
Sec-Fetch-Site: cross-site.
Referer: http://www.todobackend.com/client/index.html?http://localhost:5000.
Accept-Encoding: gzip, deflate, br.
Accept-Language: en,fr;q=0.9,de;q=0.8,es;q=0.7,zh-TW;q=0.6,zh;q=0.5,ja;q=0.4,pt;q=0.3,pl;q=0.2,fr-FR;q=0.1,en-US;q=0.1,en-GB;q=0.1.

I'm just using a fairly simple ningle app: https://github.com/fiddlerwoaroof/cl-todo-backend/blob/master/routing.lisp#L33 using the Hunchentoot handler and something isn't being setup correctly.

@fukamachi
Copy link
Owner

I think the code only runs when Content-Length or Transfer-Encoding: chunked exist. Does the todobackend.com sends those headers without Content-Type with DELETE requests?
Sorry, I couldn't try your cl-todo-backend because of a data-lens package issue.

; caught ERROR:
;   READ error during COMPILE-FILE:
;
;     Symbol "MAKE-LIST-LENS" not found in the DATA-LENS.LENSES package.
;
;       Line: 4, Column: 49, File-Position: 134
;
;       Stream: #<SB-INT:FORM-TRACKING-STREAM for "file /Users/fukamachi/Programs/etc/cl-todo-backend/lack-cors-middleware.lisp" {1001E99823}>

@fiddlerwoaroof
Copy link
Author

Ah, yeah, the relevant changes to data-lens haven't made it up to quicklisp

@fukamachi
Copy link
Owner

This was caused because the latest Http-Body assumes content-type is a string and passes to starts-with.

fukamachi/http-body@f7230c8#diff-a12cf9db7767789dad9bcd52d001cb46L14-R16

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

Successfully merging a pull request may close this issue.

2 participants