Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use More Semantic HTTP #346

Merged
merged 3 commits into from
Aug 15, 2024
Merged

Use More Semantic HTTP #346

merged 3 commits into from
Aug 15, 2024

Conversation

DanGould
Copy link
Contributor

Close #345

These are both backwards-incompatible protocol changes (old v2 vs new v2)

The first patch changes 2 POST requests for sender/receiver to a POST on a session id that establishes the fallback_psbt and a PUT on the session id that updates it to a payjoin_psbt

The second patch has a session ID establishment POST return the new resource URL (session subdirectory) in the "location" header. I'm less sure of this change than the former since it complicates the code for the sake of following "semantic" HTTP POST, but it also prevents a payjoin-directory from creating a resource in another subdirectory on a domain that a client can't easily derive.

@spacebear21 I'm hoping you can weigh in.

@DanGould DanGould requested a review from spacebear21 August 14, 2024 15:31
Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think following the REST guidelines re: the Location header is worthwhile.

If it's not a heavy lift I'd ask that we add a unit test in payjoin_directory/src/lib.rs that would help describe the expected response format for a 201 with location header and reason about it.

Comment on lines +461 to +462
format!("http://localhost:{}", port),
port,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow why port needs to be specified in the base_url and as a separate parameter. Is it just a testing/docker thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In prod, you would just pass e.g. "https://payjo.in" where the port can be assumed by the scheme (http/https), but in testing, you need to pass the explicit port because it's non-default. The base_url could be a totally separate port to the one exposed by the server if it were behind a reverse proxy or something.

Comment on lines 189 to 194
println!("BUILDER");
for field in m.header().iter() {
println!("Adding header: {:?}, {:?}", field.name(), field.value());
builder = builder.header(field.name(), field.value());
}
println!("BUILT");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover debug printlns

These features required by payjoin-directory but worked unspecified
because of a shared Cargo.lock with payjoin-cli previously specifying
hyper/full. payjoin-directory would fail if run independently without
Cargo.lock or this change, however.
A '/payjoin' suffix was used before this change instead of an HTTP method.
By using a method, we can leave control semantics mostly to the method and
have a clean {session_id} as the only path identifier to select the resource
which is augmented.
Include a 'location' header pointing to the new session resource
Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 11353f9

@DanGould DanGould merged commit ca3f400 into payjoin:master Aug 15, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Refactor Directory HTTP semantics for correctness
2 participants