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

Rewritten http package for RFC 0033 #1563

Merged
merged 3 commits into from
Feb 15, 2017
Merged

Rewritten http package for RFC 0033 #1563

merged 3 commits into from
Feb 15, 2017

Conversation

pdtwonotes
Copy link
Contributor

This is my rewrite of the net/http package, as described in RFC 33.  It also includes examples/httpget and examples/httpserver. The server example is quite limited and just shows that it works. A much more elaborate example can be found at pdtwonotes/tokara in the httpng branch.

@SeanTAllen
Copy link
Member

@pdtwonotes this needs to be rebased against master. Do you know how to do that? If not, ping me on IRC and I can help.

@SeanTAllen
Copy link
Member

@pdtwonotes there's a lot of non-standard formatting. i commented on a decent chunk of it and eventually stopped because my browser was having a hard time. i think enough should be covered to hit pretty much all the points.

i'll take a look later on after that is cleaned up for other issues.

two things i noticed, one of which i commented on.

  • there's some string concatention and that can be slow, i'd avoid that if it gets called often. there's a pony pattern for that.
  • you use error in some places. that can be slow if you expect it to get called a lot. if there are areas where it does get called a lot, can you highlight them and we can discuss if a union type would be better?

I'm really excited about replacing the old http server. Thank you for taking this on.

@pdtwonotes
Copy link
Contributor Author

pdtwonotes commented Feb 7, 2017

Where do I find these comments? And I thought I did rebase it!

// The positional parameter is the URL to be fetched.
let urlref = try env.args( env.args.size() - 1 ) else "" end
let url = try URL.valid(urlref)
else
Copy link
Member

Choose a reason for hiding this comment

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

standard library formatting would be for this else and other blocks to be on the same indentation level as the let

end

// The positional parameter is the URL to be fetched.
let urlref = try env.args( env.args.size() - 1 ) else "" end
Copy link
Member

Choose a reason for hiding this comment

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

standard library formatting would be to not have the spaces here.

(env.args.size() - 1)

" --user (-u) Username for authenticated queries\n" +
" --pass (-p) Password for authenticated queries\n" +
" --output (-o) Name of file to write response body\n"
)
Copy link
Member

Choose a reason for hiding this comment

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

standard library formatting would be for the ) to be at the end of line 56.

let _env: Env

new create( env: Env, url: URL, user: String, pass: String,
output: String ) =>
Copy link
Member

Choose a reason for hiding this comment

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

standard library formatting would be for the => to be on the next line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not see this happening very often. What is the rule?

Copy link
Member

Choose a reason for hiding this comment

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

new create( env: Env, url: URL, user: String, pass: String,
    output: String ) 
=>

when wrapping but this line is actually less than 80 characters and should be

new create(env: Env, url: URL, user: String, pass: String, output: String ) =>

Copy link
Member

@jemc jemc Feb 7, 2017

Choose a reason for hiding this comment

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

@SeanTAllen you forgot to remove the space before the ) in your example - just to let @pdtwonotes know.

Copy link
Member

Choose a reason for hiding this comment

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

@jemc i did. man this PR, it makes my browser so slow when I'm on the review page and I type something and there is a second delay before anything shows up. I'm surprised there aren't more I Fubar'd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rewrote nearly every file in the package, so it is big.

// The Notify Factory will create HTTPHandlers as required. It is
// done this way because we do not know exactly when an HTTPSession
// is created - they can be re-used.
let dumpMaker = recover val NotifyFactory.create( this ) end
Copy link
Member

Choose a reason for hiding this comment

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

create(this)

"""
_listen.dispose()
for conn in _sessions.values() do
conn.dispose()
end
Copy link
Member

Choose a reason for hiding this comment

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

formatting

for new connections. Existing connections continue to use the old routes.
Runs an HTTP server.

### Server operation
Copy link
Member

Choose a reason for hiding this comment

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

formatting is off for this section. actor/class comments get indented

an actor to deal with subsequent information pertaining to this
message.
"""
fun ref chunk( data: ByteSeq val ) => None
Copy link
Member

Choose a reason for hiding this comment

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

should be newlines between each function

essential fields filled in at this point, because ownership is being
transferred to the session actor. This begins an outbound message.
"""
be finish()
Copy link
Member

Choose a reason for hiding this comment

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

should be newline between each method

@@ -2,5 +2,6 @@ primitive DiscardLog
"""
Doesn't log anything.
"""
fun val apply(ip: String, request: Payload val, response: Payload val) =>
fun val apply(ip: String, transferred: USize,
request: Payload val, response: Payload val) =>
Copy link
Member

Choose a reason for hiding this comment

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

formatting

@SeanTAllen
Copy link
Member

@pwdnotes sorry i forgot to hit submit for the comments.

@SeanTAllen
Copy link
Member

apparently only 1 file is in conflict as you can see below.

"""
try
// This will fail if no period is found.
let dotpos = (name.rfind( ".", -1, 0 )+1).usize()
Copy link
Contributor

Choose a reason for hiding this comment

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

Standard library formatting would have no spaces between the arguments and the parentheses. Spaces should also be added around the addition so that it looks like (name.rfind(".", -1, 0) + 1).usize()

let _headers: Map[String, String] = _headers.create()
let _body: Array[ByteSeq] = _body.create()
var _body: Array[ByteSeq val] = _body.create()
Copy link
Contributor

Choose a reason for hiding this comment

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

var field is never reassigned and is only initialized with a constructor, so it should be declared with embed.

let h = handler as ResponseHandler
h(consume this, Payload.response(StatusInternalServerError))
end
None /* try
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation of None

"""
Write the response-specific parts of an HTTP message.
"""
conn.write(proto + " " + status.string() + " " + method + "\r\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

String concatenation using + here can be slow since it allocates a new string on every +

@pdtwonotes
Copy link
Contributor Author

I think the failing test is actually in error. The old version of URL.decode would decode "+" as itself, whereas in a URL "+" should decode as space. I fixed that, and that is what is breaking test test.

@sylvanc sylvanc merged commit a71d834 into ponylang:master Feb 15, 2017
@killerswan
Copy link
Member

Note #1543 for a version bump / release.

@Theodus Theodus mentioned this pull request Feb 20, 2017
@pdtwonotes pdtwonotes deleted the httpng branch February 23, 2017 04:04
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.

6 participants