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

Feature | Getters for Response Status Code & Data Length Properties #186

Merged
merged 2 commits into from Dec 30, 2020

Conversation

EstebanBorai
Copy link
Contributor

@EstebanBorai EstebanBorai commented Oct 10, 2020

Implements two methods on Response struct.

  1. status_code
  2. data_length

To act as "Getters" for these private properties in case they are needed by the client.

Im using these methods in an HTTP Server I'm writing, these could help me get both values for logging purposes.

EstebanBorai added a commit to EstebanBorai/http-server that referenced this issue Oct 10, 2020
This is a naive implementation on Request/Response logger using
a fork of `tiny-http` where the status_code and the content_length
is available.

Depends on:
- tiny-http/tiny-http#186
Copy link
Collaborator

@rawler rawler left a comment

I'm not one of the regular maintainers here, but since your PR has been long without review, I'll have a go at it.

src/response.rs Outdated
@@ -436,6 +436,16 @@ where

Ok(())
}

/// Retrieves the current value of the `Response` status code
pub fn get_status_code(&self) -> StatusCode {
Copy link
Collaborator

@rawler rawler Dec 29, 2020

Choose a reason for hiding this comment

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

I think the "get_" prefix is not used anywhere else in the public API:s of this codebase. status_code and data_length would do fine

Copy link
Contributor Author

@EstebanBorai EstebanBorai Dec 29, 2020

Choose a reason for hiding this comment

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

Sure thing! I will replace those with the names suggested!

src/response.rs Outdated

/// Retrieves the current value of the `Response` data length
pub fn get_data_length(&self) -> Option<usize> {
self.data_length.clone()
Copy link
Collaborator

@rawler rawler Dec 29, 2020

Choose a reason for hiding this comment

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

.clone() is superfluous here. Option<usize> is Copy https://doc.rust-lang.org/std/option/enum.Option.html#impl-Copy

Copy link
Contributor Author

@EstebanBorai EstebanBorai Dec 29, 2020

Choose a reason for hiding this comment

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

Ohh! Thanks for sharing! Fixing it right away!

Implements two methods on `Response` `struct`.

1. `status_code`
2. `data_length`

To act as "Getters" for these private properties in case they
are needed by the client.
@EstebanBorai EstebanBorai force-pushed the feat/getters-for-response branch from 887902e to da15188 Compare Dec 29, 2020
@EstebanBorai EstebanBorai requested a review from rawler Dec 29, 2020
rawler
rawler approved these changes Dec 30, 2020
@rawler rawler merged commit 4770db9 into tiny-http:master Dec 30, 2020
1 check passed
@EstebanBorai EstebanBorai deleted the feat/getters-for-response branch Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants