Class List Method List File List

# Class: VertxWeb::CorsHandler

Inherits:
  Object
  - Object
  - VertxWeb::CorsHandler
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb

## Overview

A handler which implements server side http://www.w3.org/TR/cors/[CORS] support for Vert.x-Web.

## Constant Summary

@@j_api_type =

      Object.new

## Class Method Summary (collapse)

- + (Boolean) accept?(obj)
- + (::VertxWeb::CorsHandler) create(allowedOriginPattern = nil)
  Create a CORS handler.
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)

## Instance Method Summary (collapse)

- - (self) allow_credentials(allow = nil)
  Set whether credentials are allowed.
- - (self) allowed_header(headerName = nil)
  Add an allowed header.
- - (self) allowed_headers(headerNames = nil)
  Add a set of allowed headers.
- - (self) allowed_method(method = nil)
  Add an allowed method.
- - (self) exposed_header(headerName = nil)
  Add an exposed header.
- - (self) exposed_headers(headerNames = nil)
  Add a set of exposed headers.
- - (void) handle(arg0 = nil)
- - (self) max_age_seconds(maxAgeSeconds = nil)
  Set how long the browser should cache the information.

## Class Method Details

### + (`Boolean`) accept?(obj)

Returns:

- (`Boolean`)

    18
    19
    20
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 18

    def @@j_api_type.accept?(obj)
      obj.class == CorsHandler
    end

### + (`::VertxWeb::CorsHandler`) create(allowedOriginPattern = nil)

Create a CORS handler

Parameters:

- allowedOriginPattern (`String`) (defaults to: `nil`) —
  the allowed origin pattern

Returns:

- (`::VertxWeb::CorsHandler`) —
  the handler

Raises:

- (`ArgumentError`)

    44
    45
    46
    47
    48
    49
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 44

    def self.create(allowedOriginPattern=nil)
      if allowedOriginPattern.class == String && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtWebHandler::CorsHandler.java_method(:create, [Java::java.lang.String.java_class]).call(allowedOriginPattern),::VertxWeb::CorsHandler)
      end
      raise ArgumentError, "Invalid arguments when calling create(#{allowedOriginPattern})"
    end

### + (`Object`) j_api_type

    27
    28
    29
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 27

    def self.j_api_type
      @@j_api_type
    end

### + (`Object`) j_class

    30
    31
    32
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 30

    def self.j_class
      Java::IoVertxExtWebHandler::CorsHandler.java_class
    end

### + (`Object`) unwrap(obj)

    24
    25
    26
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 24

    def @@j_api_type.unwrap(obj)
      obj.j_del
    end

### + (`Object`) wrap(obj)

    21
    22
    23
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 21

    def @@j_api_type.wrap(obj)
      CorsHandler.new(obj)
    end

## Instance Method Details

### - (`self`) allow_credentials(allow = nil)

Set whether credentials are allowed. Note that user agents will block requests that use a wildcard as origin and include credentials. From the MDN documentation you can read:

> Important note: when responding to a credentialed request, server must specify a domain, and cannot use wild carding.

Parameters:

- allow (`true`, `false`) (defaults to: `nil`) —
  true if allowed

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    111
    112
    113
    114
    115
    116
    117
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 111

    def allow_credentials(allow=nil)
      if (allow.class == TrueClass || allow.class == FalseClass) && !block_given?
        @j_del.java_method(:allowCredentials, [Java::boolean.java_class]).call(allow)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling allow_credentials(#{allow})"
    end

### - (`self`) allowed_header(headerName = nil)

Add an allowed header

Parameters:

- headerName (`String`) (defaults to: `nil`) —
  the allowed header name

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    63
    64
    65
    66
    67
    68
    69
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 63

    def allowed_header(headerName=nil)
      if headerName.class == String && !block_given?
        @j_del.java_method(:allowedHeader, [Java::java.lang.String.java_class]).call(headerName)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling allowed_header(#{headerName})"
    end

### - (`self`) allowed_headers(headerNames = nil)

Add a set of allowed headers

Parameters:

- headerNames (`Set<String>`) (defaults to: `nil`) —
  the allowed header names

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    73
    74
    75
    76
    77
    78
    79
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 73

    def allowed_headers(headerNames=nil)
      if headerNames.class == Set && !block_given?
        @j_del.java_method(:allowedHeaders, [Java::JavaUtil::Set.java_class]).call(Java::JavaUtil::LinkedHashSet.new(headerNames.map { |element| element }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling allowed_headers(#{headerNames})"
    end

### - (`self`) allowed_method(method = nil)

Add an allowed method

Parameters:

- method (`:OPTIONS`, `:GET`, `:HEAD`, `:POST`, `:PUT`, `:DELETE`, `:TRACE`, `:CONNECT`, `:PATCH`, `:OTHER`) (defaults to: `nil`) —
  the method to add

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    53
    54
    55
    56
    57
    58
    59
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 53

    def allowed_method(method=nil)
      if method.class == Symbol && !block_given?
        @j_del.java_method(:allowedMethod, [Java::IoVertxCoreHttp::HttpMethod.java_class]).call(Java::IoVertxCoreHttp::HttpMethod.valueOf(method.to_s))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling allowed_method(#{method})"
    end

### - (`self`) exposed_header(headerName = nil)

Add an exposed header

Parameters:

- headerName (`String`) (defaults to: `nil`) —
  the exposed header name

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    83
    84
    85
    86
    87
    88
    89
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 83

    def exposed_header(headerName=nil)
      if headerName.class == String && !block_given?
        @j_del.java_method(:exposedHeader, [Java::java.lang.String.java_class]).call(headerName)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling exposed_header(#{headerName})"
    end

### - (`self`) exposed_headers(headerNames = nil)

Add a set of exposed headers

Parameters:

- headerNames (`Set<String>`) (defaults to: `nil`) —
  the exposed header names

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    93
    94
    95
    96
    97
    98
    99
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 93

    def exposed_headers(headerNames=nil)
      if headerNames.class == Set && !block_given?
        @j_del.java_method(:exposedHeaders, [Java::JavaUtil::Set.java_class]).call(Java::JavaUtil::LinkedHashSet.new(headerNames.map { |element| element }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling exposed_headers(#{headerNames})"
    end

### - (`void`) handle(arg0 = nil)

This method returns an undefined value.

Parameters:

- arg0 (`::VertxWeb::RoutingContext`) (defaults to: `nil`)

Raises:

- (`ArgumentError`)

    35
    36
    37
    38
    39
    40
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 35

    def handle(arg0=nil)
      if arg0.class.method_defined?(:j_del) && !block_given?
        return @j_del.java_method(:handle, [Java::IoVertxExtWeb::RoutingContext.java_class]).call(arg0.j_del)
      end
      raise ArgumentError, "Invalid arguments when calling handle(#{arg0})"
    end

### - (`self`) max_age_seconds(maxAgeSeconds = nil)

Set how long the browser should cache the information

Parameters:

- maxAgeSeconds (`Fixnum`) (defaults to: `nil`) —
  max age in seconds

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    121
    122
    123
    124
    125
    126
    127
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/cors_handler.rb', line 121

    def max_age_seconds(maxAgeSeconds=nil)
      if maxAgeSeconds.class == Fixnum && !block_given?
        @j_del.java_method(:maxAgeSeconds, [Java::int.java_class]).call(maxAgeSeconds)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling max_age_seconds(#{maxAgeSeconds})"
    end