Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
Merge 2e69ca2 into 306aa8f
Browse files Browse the repository at this point in the history
  • Loading branch information
ranjanan committed Aug 11, 2018
2 parents 306aa8f + 2e69ca2 commit e386886
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 89 deletions.
9 changes: 3 additions & 6 deletions .travis.yml
Expand Up @@ -3,13 +3,10 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd()); Pkg.build("HttpParser")'
- julia -e 'Pkg.test("HttpParser", coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("HttpParser")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
10 changes: 5 additions & 5 deletions README.md
@@ -1,6 +1,6 @@
# HttpParser.jl

This package provides a Julia wrapper around Joyent's [http-parser](https://github.com/joyent/http-parser) library (v2.7.1).
This package provides a Julia wrapper around the [http-parser](https://github.com/nodejs/http-parser) library (v2.8.1).

[![Build Status](https://travis-ci.org/JuliaWeb/HttpParser.jl.svg?branch=master)](https://travis-ci.org/JuliaWeb/HttpParser.jl)
[![Coverage Status](https://coveralls.io/repos/JuliaWeb/HttpParser.jl/badge.svg?branch=master)](https://coveralls.io/r/JuliaWeb/HttpParser.jl?branch=master)
Expand All @@ -18,12 +18,12 @@ This package provides a Julia wrapper around Joyent's [http-parser](https://gith
The current `http-parser` binary for Windows is cross-compiled using `mingw-w64`.
`mingw-w64` can be installed on Ubuntu using `sudo apt-get install mingw-w64`.
To build for yourself:
* `git clone https://github.com/joyent/http-parser`
* `git clone https://github.com/nodejs/http-parser`
* `cd http-parser`
* `git checkout v2.7.1`
* `git checkout v2.8.1`
* There are currently warnings that are treated as errors. Edit the Makefile to remove -Werror
* To build 64-bit DLL: `CC=x86_64-w64-mingw32-gcc make library && mv libhttp_parser.so libhttp_parser64.dll`
* To build 32-bit DLL: `CC=i686-w64-mingw32-gcc make library && mv libhttp_parser.so libhttp_parser32.dll`
* To build 64-bit DLL: `CC=x86_64-w64-mingw32-gcc make library && mv libhttp_parser.so.2.8.1 libhttp_parser64.dll`
* To build 32-bit DLL: `CC=i686-w64-mingw32-gcc make library && mv libhttp_parser.so.2.8.1 libhttp_parser32.dll`

~~~~
:::::::::::::
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
@@ -1,4 +1,4 @@
julia 0.6
julia 0.7
HttpCommon
BinDeps
Compat 0.48.0
10 changes: 6 additions & 4 deletions appveyor.yml
@@ -1,7 +1,9 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/1.0/julia-1.0-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

Expand Down Expand Up @@ -33,8 +35,8 @@ install:
build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
- C:\projects\julia\bin\julia -e "using InteractiveUtils; versioninfo();
Pkg.clone(pwd(), \"HttpParser\"); Pkg.build(\"HttpParser\")"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"HttpParser\")"
- C:\projects\julia\bin\julia -e "using Pkg; Pkg.test(\"HttpParser\")"
29 changes: 10 additions & 19 deletions deps/build.jl
Expand Up @@ -4,7 +4,7 @@ using Compat.Libdl

@BinDeps.setup

version=v"2.7.1"
version=v"2.8.1"

aliases = []
if is_windows()
Expand All @@ -29,31 +29,22 @@ end
libhttp_parser = library_dependency("libhttp_parser", aliases=aliases,
validate=validate_httpparser)

if is_unix()
if Sys.isunix()
src_arch = "v$version.zip"
src_url = "https://github.com/nodejs/http-parser/archive/$src_arch"
src_dir = "http-parser-$version"

target = "libhttp_parser.$(Libdl.dlext)"
targetdwlfile = joinpath(BinDeps.downloadsdir(libhttp_parser),src_arch)
targetsrcdir = joinpath(BinDeps.srcdir(libhttp_parser),src_dir)
targetlib = joinpath(BinDeps.libdir(libhttp_parser),target)

patchfile = joinpath(BinDeps.depsdir(libhttp_parser), "patches", "pull-357.patch")
if version == v"2.7.1" && !isfile(joinpath(targetsrcdir, "http_parser.c.orig"))
PatchStep = (@build_steps begin
pipeline(`cat $patchfile`, `patch --verbose -b -p1 -d $targetsrcdir`)
end)
else
PatchStep = (@build_steps begin end)
end
pretarget = "libhttp_parser.$(Libdl.dlext)"
target = Compat.Sys.islinux() ? "$pretarget.$version" : "libhttp_parser.$version.$(Libdl.dlext)"
targetdwlfile = joinpath(BinDeps.downloadsdir(libhttp_parser), src_arch)
targetsrcdir = joinpath(BinDeps.srcdir(libhttp_parser), src_dir)
targetlib = joinpath(BinDeps.libdir(libhttp_parser), pretarget)

provides(SimpleBuild,
(@build_steps begin
CreateDirectory(BinDeps.downloadsdir(libhttp_parser))
FileDownloader(src_url, targetdwlfile)
FileUnpacker(targetdwlfile,BinDeps.srcdir(libhttp_parser),targetsrcdir)
PatchStep
@build_steps begin
CreateDirectory(BinDeps.libdir(libhttp_parser))
@build_steps begin
Expand All @@ -62,7 +53,7 @@ if is_unix()
FileRule(targetlib, @build_steps begin
ChangeDirectory(BinDeps.srcdir(libhttp_parser))
CreateDirectory(dirname(targetlib))
MakeTargets(["-C",src_dir,"library"], env=Dict("SONAME"=>target))
MakeTargets(["-C",src_dir,"library"], env=Dict("SONAME"=>pretarget))
`cp $src_dir/$target $targetlib`
end)
end
Expand All @@ -71,9 +62,9 @@ if is_unix()
end

# Windows
if is_windows()
if Sys.iswindows()
provides(Binaries,
URI("https://s3.amazonaws.com/julialang/bin/winnt/extras/libhttp_parser_2_7_1.zip"),
URI("https://s3.amazonaws.com/julialang/bin/winnt/extras/libhttp_parser_2_8_1.zip"),
libhttp_parser, os = :Windows)
end

Expand Down
19 changes: 0 additions & 19 deletions deps/patches/pull-357.patch

This file was deleted.

4 changes: 2 additions & 2 deletions docs/HttpParser.md
@@ -1,6 +1,6 @@
# HttpParser

This module provides a Julia wrapper around Joyent's http-parser library: [http-parser](https://github.com/joyent/http-parser)
This module provides a Julia wrapper around the http-parser library: [http-parser](https://github.com/nodejs/http-parser)

You can look at the code of HttpSever.jl as an example of using HttpParser.jl.

Expand All @@ -15,7 +15,7 @@ You can look at the code of HttpSever.jl as an example of using HttpParser.jl.

#### Installing libhttp-parser as a shared library manually

1. clone https://github.com/joyent/http-parser
1. clone https://github.com/nodejs/http-parser
2. `cd http-parser`
3. `make library # Outputs a .so file, should be a .dylib on OS X`
4. move the libhttp_parser.so to /usr/local/lib (rename to libhttp_parser.dylib if on OS X)
Expand Down
36 changes: 18 additions & 18 deletions src/HttpParser.jl
Expand Up @@ -29,7 +29,7 @@ export Parser,
id_pool = 0

# A composite type that matches bit-for-bit a C struct.
type Parser
mutable struct Parser
# parser + flag = Single byte
type_and_flags::Cuchar

Expand Down Expand Up @@ -76,17 +76,17 @@ const HTTP_CB = (Int, (Ptr{Parser},))
const HTTP_DATA_CB = (Int, (Ptr{Parser}, Ptr{Cchar}, Csize_t,))

# A composite type that is expecting C functions to be run as callbacks.
type ParserSettings
on_message_begin_cb::Ptr{Void}
on_url_cb::Ptr{Void}
on_status_complete_cb::Ptr{Void}
on_header_field_cb::Ptr{Void}
on_header_value_cb::Ptr{Void}
on_headers_complete_cb::Ptr{Void}
on_body_cb::Ptr{Void}
on_message_complete_cb::Ptr{Void}
on_chunk_header::Ptr{Void}
on_chunk_complete::Ptr{Void}
mutable struct ParserSettings
on_message_begin_cb::Ptr{Nothing}
on_url_cb::Ptr{Nothing}
on_status_complete_cb::Ptr{Nothing}
on_header_field_cb::Ptr{Nothing}
on_header_value_cb::Ptr{Nothing}
on_headers_complete_cb::Ptr{Nothing}
on_body_cb::Ptr{Nothing}
on_message_complete_cb::Ptr{Nothing}
on_chunk_header::Ptr{Nothing}
on_chunk_complete::Ptr{Nothing}
end

ParserSettings(on_message_begin_cb, on_url_cb, on_status_complete_cb, on_header_field_cb, on_header_value_cb, on_headers_complete_cb, on_body_cb, on_message_complete_cb) = ParserSettings(on_message_begin_cb, on_url_cb, on_status_complete_cb, on_header_field_cb, on_header_value_cb, on_headers_complete_cb, on_body_cb, on_message_complete_cb, C_NULL, C_NULL)
Expand All @@ -107,7 +107,7 @@ end

"Intializes the Parser object with the correct memory."
function http_parser_init(parser::Parser,isserver=true)
ccall((:http_parser_init, lib), Void, (Ptr{Parser}, Cint), &parser, !isserver)
ccall((:http_parser_init, lib), Nothing, (Ptr{Parser}, Cint), Ref(parser), !isserver)
end

"Run a request through a parser with specific callbacks on the settings instance."
Expand All @@ -128,13 +128,13 @@ end

# Is the request a keep-alive request?
function http_should_keep_alive(parser::Ptr{Parser})
ccall((:http_should_keep_alive, lib), Int, (Ptr{Parser},), Ref(parser))
ccall((:http_should_keep_alive, lib), Int, (Ptr{Parser},), Ref(parser, 1))
end

"Pauses the parser."
pause(parser::Parser) = ccall((:http_parser_pause,lib), Void, (Ptr{Parser}, Cint), Ref(parser), one(Cint))
pause(parser::Parser) = ccall((:http_parser_pause,lib), Nothing, (Ptr{Parser}, Cint), Ref(parser), one(Cint))
"Resumes the parser."
resume(parser::Parser) = ccall((:http_parser_pause,lib), Void,(Ptr{Parser}, Cint), Ref(parser), zero(Cint))
resume(parser::Parser) = ccall((:http_parser_pause,lib), Nothing,(Ptr{Parser}, Cint), Ref(parser), zero(Cint))
"Checks if this is the final chunk of the body."
isfinalchunk(parser::Parser) = ccall((:http_parser_pause,lib), Cint, (Ptr{Parser},), Ref(parser)) == 1

Expand All @@ -143,7 +143,7 @@ errno(parser::Parser) = parser.errno_and_upgrade & 0b01111111
errno_name(errno::Integer) = unsafe_string(ccall((:http_errno_name,lib),Cstring,(Int32,),errno))
errno_description(errno::Integer) = unsafe_string(ccall((:http_errno_description,lib),Cstring,(Int32,),errno))

immutable HttpParserError <: Exception
struct HttpParserError <: Exception
errno::Int32
HttpParserError(errno::Integer) = new(Int32(errno))
end
Expand All @@ -160,7 +160,7 @@ show(io::IO, err::HttpParserError) = print(io,"HTTP Parser Exception: ",errno_na
UF_USERINFO = Cint(6),
UF_MAX = Cint(7))

immutable ParserUrl
struct ParserUrl
field_set::UInt16 # Bitmask of (1 << UF_*) values
port::UInt16 # Converted UF_PORT string
field_data::NTuple{Cint(UF_MAX)*2, UInt16}
Expand Down
30 changes: 15 additions & 15 deletions test/runtests.jl
@@ -1,8 +1,8 @@
using HttpParser
using HttpCommon
using Base.Test
using Compat
import Compat: String
using Compat: @info
using Compat.Test

FIREFOX_REQ = tuple("GET /favicon.ico HTTP/1.1\r\n",
"Host: 0.0.0.0=5000\r\n",
Expand Down Expand Up @@ -108,18 +108,18 @@ function on_chunk_complete(parser)
return 0
end

c_message_begin_cb = cfunction(on_message_begin, HttpParser.HTTP_CB...)
c_url_cb = cfunction(on_url, HttpParser.HTTP_DATA_CB...)
c_status_complete_cb = cfunction(on_status_complete, HttpParser.HTTP_CB...)
c_header_field_cb = cfunction(on_header_field, HttpParser.HTTP_DATA_CB...)
c_header_value_cb = cfunction(on_header_value, HttpParser.HTTP_DATA_CB...)
c_headers_complete_cb = cfunction(on_headers_complete, HttpParser.HTTP_CB...)
c_body_cb = cfunction(on_body, HttpParser.HTTP_DATA_CB...)
c_message_complete_cb = cfunction(on_message_complete, HttpParser.HTTP_CB...)
c_body_cb = cfunction(on_body, HttpParser.HTTP_DATA_CB...)
c_message_complete_cb = cfunction(on_message_complete, HttpParser.HTTP_CB...)
c_chunk_header_cb = cfunction(on_chunk_header, HttpParser.HTTP_CB...)
c_chunk_complete_cb = cfunction(on_chunk_complete, HttpParser.HTTP_CB...)
c_message_begin_cb = @cfunction(on_message_begin, Int, (Ptr{Parser},))
c_url_cb = @cfunction(on_url, Int, (Ptr{Parser}, Ptr{Cchar}, Csize_t,))
c_status_complete_cb = @cfunction(on_status_complete, Int, (Ptr{Parser},))
c_header_field_cb = @cfunction(on_header_field, Int, (Ptr{Parser}, Ptr{Cchar}, Csize_t,))
c_header_value_cb = @cfunction(on_header_value, Int, (Ptr{Parser}, Ptr{Cchar}, Csize_t,))
c_headers_complete_cb = @cfunction(on_headers_complete, Int, (Ptr{Parser},))
c_body_cb = @cfunction(on_body, Int, (Ptr{Parser}, Ptr{Cchar}, Csize_t,))
c_message_complete_cb = @cfunction(on_message_complete, Int, (Ptr{Parser},))
c_body_cb = @cfunction(on_body, Int, (Ptr{Parser}, Ptr{Cchar}, Csize_t,))
c_message_complete_cb = @cfunction(on_message_complete, Int, (Ptr{Parser},))
c_chunk_header_cb = @cfunction(on_chunk_header, Int, (Ptr{Parser},))
c_chunk_complete_cb = @cfunction(on_chunk_complete, Int, (Ptr{Parser},))

function init(test::Tuple)
# reset request
Expand Down Expand Up @@ -225,4 +225,4 @@ HttpParser.resume(p)
ex = HttpParser.HttpParserError(0x1f)
@test ex.errno == 0x1f

info("All assertions passed!")
@info "All assertions passed!"

0 comments on commit e386886

Please sign in to comment.