Skip to content

Play button requests from local docs return 400 bad request - CORS? #194

@carols10cents

Description

@carols10cents

What happened

I ran rustup doc --book to open the book from my local copy of the docs. I went to .rustup/toolchains/stable-x86_64-apple-darwin/share/doc/rust/html/book/second-edition/ch01-02-hello-world.html and clicked the play button for the first example under the "Writing and Running a Rust Program" header, which contains:

fn main() {
    println!("Hello, world!");
}

The UI just shows "Running..." and never shows results or an error message.

Inspecting the network tab shows an OPTIONS request to https://play.rust-lang.org/evaluate.json returned 400 Bad Request. The request headers are as follows:

OPTIONS /evaluate.json HTTP/1.1
Host: play.rust-lang.org
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:57.0) Gecko/20100101 Firefox/57.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Origin: null
Connection: keep-alive

Requests from file:/// for local docs have null for the Origin, and the playground has its CORS set not to allow these kinds of requests.

Are there any negative consequences to allowing these requests via CORS?

Metadata

Metadata

Assignees

Labels

bugThe playground isn't doing what it was intended to

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions