Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multipart HTTP response from a web server is being downloaded instead of parsed

I’m trying to create a simple web server in rust, but I’m running into some trouble.

When the web server is responding to an HTTP request for a website page, the server gets the associated HTML, JS, and CSS files and compiles them into a multipart HTTP response. Yet, instead of the response being parsed by the browser (in my case Firefox) and displaying the HTML and CSS and executing the JS, it downloads the multipart HTTP response as a file (no extension).

This is response to the client (the file downloaded excludes the top 3 lines):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

HTTP/1.1 200 OK
Content-Type: multipart/mixed; boundary=boundary

--boundary
Content-Disposition: inline; filename="index.html"
Content-Type: text/html
Content-Length: 268

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Hello</title>

    <script src="index.js"></script>
    <link rel="stylesheet" href="index.css">
  </head>
  <body>
    <h1>Hi, this is a website!</h1>
  </body>
</html>
--boundary
Content-Type: text/javascript
Content-Disposition: inline; filename="index.js"
Content-Length: 49

function alert(){  
    alert("Hello!");  
}
--boundary
Content-Type: text/css
Content-Disposition: inline; filename="index.css"
Content-Length: 54

body {
    background-color: rgb(212, 193, 145);
  }
--boundary--

I have tried altering the Content-Dispostion headers, specifically inline, as well the carriage returns and line feeds in an attempt to hopefully match the proper formatting, but nothing has worked.

If you have any suggestions or know where I’m going wrong with the formatting, please let me know

>Solution :

Browsers do not support parsing and displaying multipart HTTP responses.

It isn’t working, not because you are getting the format wrong, but because the format isn’t supported at all.

You could get similar behaviour by implementing HTTP 2.0 with server push.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading