Comments (9)
I also tried:
new Deno.Command("curl", {
args: [
"https://slumbot.com/api/new_hand",
"--header",
"'Content-Type: application/json'",
"-d",
"'{}'",
],
}).output().then(($) => console.log(new TextDecoder().decode($.stdout)));
from slumbot2019.
The header should be "Content-Type", not "content-type".
In your second example (with "curl"), I'm not sure why you have the single quotes (e.g., before Content-Type). That could throw things off if they are not stripped somehow.
from slumbot2019.
I assumed headers are case-insensitive, as per rfc7230, but when changing their case, the Typescript fetch
doesn't work.
fetch("https://slumbot.com/api/new_hand", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: "{}",
}).then(console.log);
For the second (Deno.Command), removing the single quotes from the header and body worked, i.e. the program's call to curl
returned a successful response. This is why I suspect something in the way Javascript's fetch API makes requests is to blame. I noticed in the response object, the headers are converted to lowercase:
Response {
body: ReadableStream { locked: false },
bodyUsed: false,
headers: Headers {
connection: "keep-alive",
"content-length": "0",
"content-type": "application/json",
date: "Tue, 18 Jun 2024 12:32:41 GMT",
server: "nginx/1.18.0 (Ubuntu)"
},
ok: false,
redirected: false,
status: 400,
statusText: "Bad Request",
url: "https://slumbot.com/api/new_hand"
}
There's no option to change this behavior, so if the server treats (required) headers case-sensitively, it may be impossible to make requests from Javascript.
from slumbot2019.
I think you're right. I'll change the server code to be case-insensitive in handling HTTP headers and we'll see if that fixes things. Should be able to do this today or tomorrow.
from slumbot2019.
I've pushed the fix to be case-insensitive in parsing HTTP headers. Can you try again to see if you can access the API using fetch() from Javascript?
from slumbot2019.
Running the code from the original post yielded the same (400) response.
Is requiring the content-type header necessary? Presumably, non-JSON bodies would fail regardless.
from slumbot2019.
I think the header parsing is still case-sensitive (as opposed to another unique characteristic of fetch
), cause this failed:
curl -s https://slumbot.com/api/new_hand --header "content-type: application/json" -d "{}"
and this succeeded:
curl -s https://slumbot.com/api/new_hand --header "Content-Type: application/json" -d "{}"
from slumbot2019.
Oh, shoot, I hadn't pushed the libraries containing the fix.
Now I think I've pushed the fix and the curl command you provided (with lower-case content-type) is now working. Please try again.
from slumbot2019.
Yep, works now. Thanks for the fix.
from slumbot2019.
Related Issues (20)
- solve_all_subgames or solve_all_backup_subgames encounter segmentfault
- No response from server on slumbot.com HOT 6
- [Security] Slumbot accepts illegal actions, allowing user to cheat HOT 4
- Slumbot does not raise the nuts on the river HOT 1
- [API] Include more baseline details at end of hand
- Server Down HOT 1
- Invalid actions? HOT 2
- Slumbot bet size too small HOT 3
- Slumbot betsize error HOT 1
- Leaderboard empty HOT 1
- BUG: MPTree doesnt work with holdem params HOT 5
- mp_betting_tree CreateMPStreet error HOT 2
- show_probs_at_node segmentation fault HOT 1
- Poker Solver HOT 1
- Error with build_unique_buckets
- Website and server down HOT 10
- Unable to access the API via sample_api python script. HOT 2
- Bug on Straight Flush Winning Calculation ? HOT 4
- Help building local version of API HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slumbot2019.