Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few things. First, to your concern about the 400 errors you are getting back, a few possibilities come to mind:</p> <ul> <li>"Host:" isn't actually a valid header field in HTTP/1.0, and depending on how fascist the web server you are contacting is about standards, it would reject this as a bad request based on the protocol you claim to be speaking.</li> <li>You need a CRLF between your Request-line and each of the header lines.</li> <li>It is possible that your (request) function is returning something for the Request-URI field -- you substitute in the value of request as the contents of this part of the Request-line -- that is bogus in one way or another (badly escaped characters, etc.). Seeing what it is outputting might help out some.</li> </ul> <p>Some other more general pointer to help you along your way:</p> <ul> <li><p>(read-buf-nonblock) is very confusing. Where is the symbol 'c' defined? Why is 'eof' (gensym)ed and then not assigned any value? It looks very much like a byte-by-byte copy taken straight out of an imperative program, and plopped into Lisp. It looks like what you have reimplemented here is (read-sequence). Go look <a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_rd_seq.htm" rel="nofollow noreferrer">here</a> in the Common Lisp Hyperspec, and see if this is what you need. The other half of this is to set your socket you created to be non-blocking. This is pretty easy, even though the SBCL documentation is almost silent on the topic. Use this:</p> <p><code>(socket-make-stream socket :input t :output t :buffering :none :timeout 0)</code></p></li> <li><p>The last (let) form of (http-connect) isn't necessary. Just evaluate </p> <p><code>(socket-make-stream socket :input t :output t :buffering :none)</code></p></li> </ul> <p>without the let, and http-connect should still return the right value.</p> <ul> <li>In (http-request)...</li> </ul> <p>Replace:</p> <pre><code> (format stream "~a~%~%" request ) (let ((data (make-string buffer))) (setf data (subseq data 0 (read-buf-nonblock data stream))) (princ data) (&gt; (length data) 0))) </code></pre> <p>with</p> <pre><code>(format stream "~a~%~%" request ) (let ((data (read-buf-nonblock stream))) (princ data) (&gt; (length data) 0))) </code></pre> <p>and make (read-buf-nonblock) return the string of data, rather that having it assign within the function. So where you have <code>buffer</code> being assigned, create a variable <code>buffer</code> within and then return it. What you are doing is called relying on "side-effects," and tends to produce more errors and harder to find errors. Use it only when you have to, especially in a language that makes it easy not to depend on them.</p> <ul> <li>I mostly like the the way get-page is defined. It feels very much in the functional programming paradigm. However, you should either change the name of the (request) function, or the variable request. Having both in there is confusing.</li> </ul> <p>Yikes, hands hurt. But hopefully this helps. Done typing. :-)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload