1

in pset6 what should be the response if we make request from telnet program as GET / hello.html HTTP/1.1? The staff solution report the error as "HTTP/1.1 505 HTTP Version Not Supported" even though version is HTTP/1.1 only and my implementation reports "HTTP/1.1 400 Bad Request" so which is the correct error report for such request to server? Thank you!

1

Most servers will return bad request 400 (not 505) if target-URI contains un-escaped spaces

Presumably, the issue is the space (SP) between / and hello.html .

Have you written code to count the number of spaces and ensure it's two, calling error(400) if it's not?

It would appear the staff implementation has not done this, and probably ends up splitting the request like so:

  • method: "GET"
  • request-target "/"
  • version: "hello.html" or "hello.html HTTP/1.1"

There's some debate online over whether this should return 400 or 505, but here are a few quotes from this conversation: https://bz.apache.org/bugzilla/show_bug.cgi?id=42750

the response should probably be a 400 Bad Request.

...

It is true that in the RFC the Request line is made up of single spaced elements, but if you look at appendix b (https://www.rfc-editor.org/rfc/rfc1945#page-55) it says " Clients should be tolerant in parsing the Status-Line and servers tolerant when parsing the Request-Line. In particular, they should accept any amount of SP or HT characters between fields, even though only a single SP is required."

I thought a good way to follow up would be to just telnet google and see how it handles it:

jharvard@appliance (~): telnet www.google.com 80
Trying 216.58.219.68...
Connected to www.google.com.
Escape character is '^]'.
GET / ?=cat HTTP/1.1

HTTP/1.0 400 Bad Request
Content-Type: text/html; charset=UTF-8
Content-Length: 1555
Date: Mon, 21 Sep 2015 17:02:20 GMT
Server: GFE/2.0

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 400 (Bad Request)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>400.</b> <ins>That���s an error.</ins>
  <p>Your client has issued a malformed or illegal request.  <ins>That���s all we know.</ins>
Connection closed by foreign host.

and cs50!

jharvard@appliance (~): telnet www.cs50.harvard.edu 80
Trying 54.165.135.195...
Connected to www.cs50.harvard.edu.
Escape character is '^]'.
GET / seminars HTTP/1.1
HTTP/1.1 400 BAD_REQUEST
Content-Length: 0
Connection: Close

Connection closed by foreign host.

Both of which flag it as a bad request, 400. It looks like your handling of injected un-escaped spaces is more similar to real servers than the staff's.

Interestingly, google parsed this request

"GET         /?q=cat      HTTP/1.1"

without issue, while cs50's server threw a 400 when fed

"GET     /seminars   HTTP/1.1"

indicating that cs50's server is not as tolerant as the RFC appendix recommends?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .