0

I got stuck a while back on load, put this pset down, moved on to complete (and thoroughly enjoy) pset7, but I don't like that I didn't finish this one.

Here's what is happening: when I start the server and click on an .html file, it downloads rather than opens directly. When I open one in Chrome, I see close to accurate code except in the case where I open a page with shorter code after one with longer code. Also, cat.jpg doesn't display (probably because I have extra bytes at the end).

I feel like I am so close, but I am struggling to get my memory allocation just right. Below is what I have for load. Any tips would be greatly appreciated. I really want to figure this out and move on to mashup to finish up the psets. Thanks!

Original code removed - Please see revision below

Per academic honesty, correct load code removed

I added the printf as a sanity check, and this is what I see in the terminal:

GET /hello.html HTTP/1.1
<!DOCTYPE html>

<html>
    <head>
        <title>hello</title>
    </head>
    <body>
        <form action="hello.php" method="get">
            <input autocomplete="off" autofocus name="name" placeholder="Name" type="text"/>
            <input type="submit" value="Say Hello"/>
        </form>
    </body>
</html>
HTTP/1.1 200 OK
GET /cat.html HTTP/1.1
<!DOCTYPE html>

<html>
    <head>
        <title>Happy Cat</title>
    </head>
    <body>
        <img alt="Happy Cat" src="cat.jpg"/>
    </body>
</html>
HTTP/1.1 200 OK

The HTML looks okay. The longer code is not appended to the shorter code, but it's still not showing cat.jpg and all the files are downloading rather than displaying properly.

2
  • Your new load function moots the original answer, so it has been deleted. If you're getting download instead of web page, look to lookup. If longer code is appended to shorter code, look to proper termination of abs_path. Be sure to post an answer once you find it! – DinoCoderSaurus Jul 21 '16 at 13:35
  • Thank you for pointing me in the right direction. I had a minor bug in lookup and another in parse. In the former I wasn't handling php files correctly and add a forward slash at the front of each file type. In the latter, I also wasn't handling php files correctly with respect to query and abs_path. After fixing those errors, indexes was a breeze. Passed check50 and submitted! – Peter Jul 21 '16 at 20:08
0

Moral of the story: read the spec carefully and don't rely on the first check50 for correctness of lookup and parse. Test them abundantly, especially when it comes to PHP files. Use inspect element when possible and compare it to the output of the staff solution.

You must log in to answer this question.

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