Re: [racket-users] How to obtain the public IP of the sender of an HTTP request?

2018-04-17 Thread Matthew Butterick
PS if you're running the Racket web server as a proxy behind Apache, then 
`request-client-ip` will always be the localhost IP. However, Apache stores the 
original request IP in special header called X-Forwarded-For [1] which can be 
retrieved like so:

(dict-ref (request-headers req) 'x-forwarded-for)

[1] http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#x-headers



> On 17 Apr 2018, at 1:59 PM, David Storrs  wrote:
> 
> Ugh.  How did I miss that?  Thanks, Jay.
> 
> On Tue, Apr 17, 2018 at 4:31 PM, Jay McCarthy  wrote:
>> request-client-ip on the request object your handler gets.
>> 
>> Jay

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to obtain the public IP of the sender of an HTTP request?

2018-04-17 Thread David Storrs
Ugh.  How did I miss that?  Thanks, Jay.

On Tue, Apr 17, 2018 at 4:31 PM, Jay McCarthy  wrote:
> request-client-ip on the request object your handler gets.
>
> Jay
>
> On Tue, Apr 17, 2018 at 2:54 PM, David Storrs  wrote:
>> Assume I'm a web server and one of the requests I want to respond to
>> is "What is my public IP address?"  More specifically, if the server
>> receives an HTTP request to, let's say, the ".../get-ip" endpoint then
>> it should send back an HTTP response containing the sender's public
>> IP.  cf https://www.ipchicken.com/ for a real example.
>>
>> This information is available in the IP connection data
>> (https://en.wikipedia.org/wiki/IPv4#Source_address) but I'm not sure
>> how to get access to that from within the web-server/* packages.  I've
>> been wikiwalking through the docs and am coming up empty.
>>
>> I'm starting a pretty vanilla server like so:
>>
>> (define-values (dispatch-request url-for)
>>   (dispatch-rules
>> ...stuff...
>> ))
>>
>>   (serve/servlet dispatch-request
>>  #:launch-browser? #f
>>  #:servlet-regexp #px""
>>  #:listen-ip #f
>>  #:port (port-num)
>>  #:log-file log-path
>>  )
>>
>> I recognize that the Source Address in the packet can and probably
>> will be changed when it runs through a NAT layer, but that's
>> acceptable in my use case.
>>
>> Any pointers?
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
> -=[ Moses 1:33: And worlds without number have I created; ]=-

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to obtain the public IP of the sender of an HTTP request?

2018-04-17 Thread Jay McCarthy
request-client-ip on the request object your handler gets.

Jay

On Tue, Apr 17, 2018 at 2:54 PM, David Storrs  wrote:
> Assume I'm a web server and one of the requests I want to respond to
> is "What is my public IP address?"  More specifically, if the server
> receives an HTTP request to, let's say, the ".../get-ip" endpoint then
> it should send back an HTTP response containing the sender's public
> IP.  cf https://www.ipchicken.com/ for a real example.
>
> This information is available in the IP connection data
> (https://en.wikipedia.org/wiki/IPv4#Source_address) but I'm not sure
> how to get access to that from within the web-server/* packages.  I've
> been wikiwalking through the docs and am coming up empty.
>
> I'm starting a pretty vanilla server like so:
>
> (define-values (dispatch-request url-for)
>   (dispatch-rules
> ...stuff...
> ))
>
>   (serve/servlet dispatch-request
>  #:launch-browser? #f
>  #:servlet-regexp #px""
>  #:listen-ip #f
>  #:port (port-num)
>  #:log-file log-path
>  )
>
> I recognize that the Source Address in the packet can and probably
> will be changed when it runs through a NAT layer, but that's
> acceptable in my use case.
>
> Any pointers?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
-=[ Jay McCarthy   http://jeapostrophe.github.io]=-
-=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
-=[ Moses 1:33: And worlds without number have I created; ]=-

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Reimplementing Hackett’s type language: expanding to custom core forms in Racket

2018-04-17 Thread Stephen Chang
Hi Alexis,

Great article. And timely too, since it addresses some of the same
usage issues of local-expand and stoplists that we ran into with
Turnstile.

(I'm also interested in why the core forms are added to the stop list.
Is it because of let-syntax? I know it's probably been mentioned
before but I wasn't able to find an explanation in the docs or
archive.)

Specifically, we (Michael Ballantyne) recently added stoplists for
terms, but we're still experimenting with the right representation for
types.

In our experimentation we manually implemented the recursive,
stop-listed expansions like you did (but it wasny as elegant as your
syntax classes). I eventually ran into the same issue with binding
types and passing the context, so it was good to see a solution worked
all the way through, and written up nicely.

In the future, I would love to receive notification about any new blog posts.

On Sun, Apr 15, 2018 at 10:38 AM, David Thrane Christiansen
 wrote:
> Hi Alexis,
>
> I am very happy to have posts like this announced here. Thanks for writing
> it! It was useful and interesting.
>
> David
>
> On Sun, Apr 15, 2018, 06:58 Alexis King  wrote:
>>
>> Hello all,
>>
>> I wrote a blog post about my recent experience rewriting the
>> implementation of Hackett’s internal type representation, and on writing
>> languages that expand to custom core forms in Racket in general. For
>> those interested in Hackett and/or (ab)uses of some of the lesser-known
>> features of Racket’s macro system, you might be interested:
>>
>>
>> https://lexi-lambda.github.io/blog/2018/04/15/reimplementing-hackett-s-type-language-expanding-to-custom-core-forms-in-racket/
>>
>> I’ve refrained in the past from posting my blog to this list, since it
>> does not seem like something other people normally do and many of the
>> interested parties seem to find it through some other channel. Still, I
>> thought I’d try posting it here this time. Feedback is welcome and
>> appreciated, both on the blog post itself and on whether or not people
>> appreciate posting things like this to this list.
>>
>> Alexis
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] How to obtain the public IP of the sender of an HTTP request?

2018-04-17 Thread David Storrs
Assume I'm a web server and one of the requests I want to respond to
is "What is my public IP address?"  More specifically, if the server
receives an HTTP request to, let's say, the ".../get-ip" endpoint then
it should send back an HTTP response containing the sender's public
IP.  cf https://www.ipchicken.com/ for a real example.

This information is available in the IP connection data
(https://en.wikipedia.org/wiki/IPv4#Source_address) but I'm not sure
how to get access to that from within the web-server/* packages.  I've
been wikiwalking through the docs and am coming up empty.

I'm starting a pretty vanilla server like so:

(define-values (dispatch-request url-for)
  (dispatch-rules
...stuff...
))

  (serve/servlet dispatch-request
 #:launch-browser? #f
 #:servlet-regexp #px""
 #:listen-ip #f
 #:port (port-num)
 #:log-file log-path
 )

I recognize that the Source Address in the packet can and probably
will be changed when it runs through a NAT layer, but that's
acceptable in my use case.

Any pointers?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] [racket] error : Attempted to use a higher-order value passed as `Any` in untyped code:

2018-04-17 Thread Alex Knauth
This is interesting. The `Any` type in Typed Racket includes values that may 
have higher-order "original" types. For example, it may have originally been a 
typed function (-> Fixnum Fixnum) or (-> String Boolean), such that if you call 
it without a contract guarding it, it should be an error. This is because `Any` 
is a super type of those types.

However, the value returned by `dynamic-require` is different from a normal 
`Any`. It will never be an unguarded "originally" typed value, so it should be 
safe to pass it to `cast` without adding a new guard. It might make sense to 
define a new type `UntypedAny` or maybe `GuardedAny`. There are two differences:
  (1) this type is *not* a super type of any other type that might involve 
higher-order values
  (2) it is safe to pass a value of this type into untyped code without an 
additional guard

Point (2) is what would allow `cast` to work, and point (1) is what would make 
that safe to do.

With this new `UntypedAny` type, dynamic-require could return the type 
`UntypedAny` instead of `Any`.

--

Why this would allow `cast` to work (and why `require/typed` is a good 
workaround for now)

The difference between `cast` and `require/typed` is this:
 - `require/typed` guards value going from Untyped -> Typed
 - `cast` guards values going from Typed -> Untyped -> Typed

The `cast` needs the extra Typed -> Untyped boundary to guard "originally" 
typed higher-order values, such as a (-> Fixnum Fixnum) function annotated as 
`Any`. However, `require/typed` takes its values from an untyped context to 
begin with, so it doesn't need to deal with that extra boundary.

The value returned by `dynamic-require` is never one of those typed 
higher-order values, and if the type system knows that through the `UntypedAny` 
type, the type system will know it is safe to make `cast` behave like 
`require/typed`.

It will know it is safe to pass it only through the Untyped -> Typed boundary.

Alex Knauth

> On Apr 16, 2018, at 10:01 AM, Matthias Felleisen  
> wrote:
> 
> 
> Have you considered organizing your program as follows: 
> 
> #lang racket
> 
> (module a racket
>   (provide f)
>   (define (f x) 10))
> 
> (module b racket
>   (provide g)
>   (define g (dynamic-require '(submod "foo.rkt" a) 'f)))
> 
> (module c typed/racket
>   (require/typed (submod ".." b) [g (-> Integer Integer)])
>   (g 20))
> 
> (require 'c)
> 
> That is, run the dynamic-require in an untyped module and then import it at 
> the desired type? 
> 
> 
> 
>> On Apr 16, 2018, at 5:22 AM, mailoo > > wrote:
>> 
>> 
>> Hello,
>> 
>> I'm new to racket, and even more with typed/racket.
>> 
>> I play a little with the "Any" type (due to 'dynamic-require' which return 
>> Any), and I'm not able to cast them back in a function.
>> 
>> I (over) simplify my question with this little program :
>> 
>> ```
>> (: p Any)
>> (define (p i) (displayln i))
>> 
>> ; Here I want to get back my function
>> (define proc (cast p (-> Integer Void)))
>> (proc 2)
>> 
>> ```
>> 
>> but I get this error when I try to execute the function :
>> 
>> ```
>> ; contract violation
>> ;   Attempted to use a higher-order value passed as `Any` in untyped code: 
>> #
>> ;   in: Any
>> ;   contract from: typed-world
>> ;   blaming: cast
>> ;(assuming the contract is correct)
>> ;   at: /racketFBP/test.rkt:13.13
>> ; Context:
>> ;  /home/denis/dev/racket/racketFBP/test.rkt:1:1 [running body]
>> ; [Due to errors, REPL is just module language, requires, and stub 
>> definitions]
>> ```
>> 
>> In reality, I get my function by `(dynamic-require path 'p)`, and I didn't 
>> find a typed version of this function...
>> 
>> Is there a way to go from Any to a function, or to replace my use of 
>> `dynamic-require`?
>> 
>> Thank you in advance,
>> Denis Michiels
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com 
>> .
>> For more options, visit https://groups.google.com/d/optout 
>> .
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.