* Refactor bug-related url construction

* Add captcha url (unused, yet)

* The second argument to `call/input-url' can be a one-argument function
  since the call doesn't send it any headers.

Still needs to be done: check the HTTP response for an error status, and
make it fail as a result (currently it just assumes that any response is
fine, which can change in case of a captcha failure).  Then, add a
captcha challenge if one is found, otherwise ignore.
This commit is contained in:
Eli Barzilay 2011-05-31 17:36:34 -04:00
parent b43e956c7b
commit 4276898a67
2 changed files with 16 additions and 18 deletions

View File

@ -16,8 +16,10 @@
saved-bug-report-titles/ids
discard-all-saved-bug-reports)
(define bug-www-server "bugs.racket-lang.org")
(define bug-www-server-port 80)
(define (bug-server-url path)
(string->url (string-append "http://bugs.racket-lang.org/" path)))
(define bug-report-url (bug-server-url "bug-report.cgi"))
(define captcha-text-url (bug-server-url "captcha-text"))
(preferences:set-default 'drracket:email "" string? #:aliases '(drscheme:email))
(preferences:set-default 'drracket:full-name "" string? #:aliases '(drscheme:full-name))
@ -191,10 +193,6 @@
;; initiates sending the bug report and switches the GUI's mode
(define (send-bug-report)
(define query (get-query))
(define url
(string->url (format "http://~a:~a/cgi-bin/bug-report"
bug-www-server
bug-www-server-port)))
(define post-data
(parameterize ([current-alist-separator-mode 'amp])
(string->bytes/utf-8 (alist->form-urlencoded query))))
@ -207,11 +205,9 @@
(λ ()
(with-handlers ([exn:fail? (λ (x) (channel-put exn-chan x))])
(parameterize ([current-alist-separator-mode 'amp])
(call/input-url
url
(case-lambda
[(x) (post-pure-port x post-data)]
[(x y) (post-pure-port x post-data y)])
(call/input-url
bug-report-url
(lambda (x) (post-pure-port x post-data))
(lambda (port)
(define response-text (new html-text%))
(render-html-to-text port response-text #t #f)

View File

@ -261,11 +261,13 @@
(define captcha-text
;; This is currently empty -- help/bug-report.rkt will poll it for
;; text that is used for a captcha challenge question, and if it's not
;; empty, then it will show that in the dialog. It's intended to be
;; used in the future if spam bug reports that use drracket (or racket
;; code) directly become a problem. In this case, adding a challenge
;; here will make existing installations start asking for an answer.
;; (And this could be done with a changes-on-each-build basis, or some
;; script that will create and remember short-lived captcha
;; challenges.)
;; empty, then it will show that in an input dialog. It's intended to
;; be used in the future if spam bug reports that use drracket (or
;; racket code) directly become a problem. In this case, adding a
;; challenge here will make existing installations start asking for an
;; answer. (And this could be done with a changes-on-each-build
;; basis, or some script that will create and remember short-lived
;; captcha challenges.) Note that the text should be a complete text
;; for a question, including a "?" and instructions. It is used as is
;; in the `message' argument for `get-text-from-user'.
@plain[#:file "captcha-text" #:newline #f]{})