Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7973957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:14:46+00:00 2026-06-04T08:14:46+00:00

Given this snippet: (defroutes main-routes (POST /input/:controller request (let [buff (ByteArrayOutputStream.)] (copy (request :body)

  • 0

Given this snippet:

(defroutes main-routes
    (POST "/input/:controller" request
        (let [buff (ByteArrayOutputStream.)]
            (copy (request :body) buff) 
            ;; --- snip

The value of buff will be a non-empty byte array iff there’s the Content-Type header in the request. The value can be nonsencial, the header just has to be there.

However, I need to dump the body (hm… that came out wrong) if the request came without a content type, so that the client can track down the offending upload. (The uploading software is not under my control and its maintainers won’t provide anything extra in the headers.)

Thank you for any ideas on how to solve or work around this!

EDIT:

Here are the headers I get from the client:

{
   "content-length" "159",
   "accept" "*/*",
   "host" (snip),
   "user-agent" (snip)
}

Plus, I discovered that Ring, using an instance of Java’s ServletRequest, fills in the content type with the standard default, x-www-form-urlencoded. I’m now guessing that HTTPParser, which supplies the body through HTTPParser#Input, can’t parse it correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:14:48+00:00Added an answer on June 4, 2026 at 8:14 am

    I face the same issue. It’s definitely one of the middleware not being able to parse the body correctly and transforming :body. The main issue is that the Content-Type suggest the body should be parsable.

    Using ngrep, I found out how curl confuses the middleware. The following, while intuitive (or rather sexy) on the command line sends a wrong Content-Type which confuses the middleware:

    curl -nd "Unknown error" http://localhost:3000/event/error                                                                            
    
    T 127.0.0.1:44440 -> 127.0.0.1:3000 [AP]
    POST /event/error HTTP/1.1.
    Authorization: Basic SzM5Mjg6ODc2NXJkZmdoam5idmNkOQ==.
    User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3.
    Host: localhost:3000.
    Accept: */*.
    Content-Length: 13.
    Content-Type: application/x-www-form-urlencoded.
    .
    Unknown error
    

    The following however forces the Content-Type to being opaque and the middleware will not interfere with the :body.

    curl -nd "Unknown error" -H "Content-Type: application/data" http://localhost:3000/event/error                                        
    
    T 127.0.0.1:44441 -> 127.0.0.1:3000 [AP]
    POST /event/error HTTP/1.1.
    Authorization: Basic SzM5Mjg6ODc2NXJkZmdoam5idmNkOQ==.
    User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3.
    Host: localhost:3000.
    Accept: */*.
    Content-Type: application/data.
    Content-Length: 13.
    .
    Unknown error
    

    I’m considering replacing the middleware with a more liberal one because even though the request is wrong, I’d still like to be able to decide what to do with the body myself. It’s a really weird choice to zero the request body when the request doesn’t make sense. I actually think a more correct behavior would be to pass it to an error handler which by default would return a 400 Bad Request or 406 Not Acceptable.

    Any thoughts on that? In my case I might propose a patch to Compojure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this snippet of OCaml code: let rec range a b = if a
Given this code snippet that can be readily pasted into Linqpad (or slightly modified
Given this snippet of code: funcs = [] for x in range(3): funcs.append(lambda: x)
Given this code snippet, I know that if the user selects 25c the value
this snippet of code is given me headache. Personally, I would like to use
Given this simple code snippet I am astounded to provoke a stack overflow this
Given this snippet from Blah.dll's AssemblyInfo.cs: [assembly: AssemblyVersion(3.3.3.3)] [assembly: AssemblyFileVersion(2.2.2.2)] And then in a
Given this HTML snippet: <div id=box style=overflow:auto; width:200px; height:200px; border:1px solid black;> 1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br> 11<br>12<br>13<br>14<br>15<br>16<br>17<br>18<br>19<br>20<br>
Given this XML Schema snippet: <xs:element name=data> <xs:complexType> <xs:sequence> <xs:element name=param type=param minOccurs=0 maxOccurs=unbounded
Given this XML/XHTML snippet: <h1> <zuq:data name=siteHeader /> </h1> <h2> <zuq:data name=pageHeaderName /> <span>&mdash;</span>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.